From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: "n.pettik" <korablev@tarantool.org>, tarantool-patches@freelists.org Subject: [tarantool-patches] Re: [PATCH 4/9] sql: introduce type boolean Date: Wed, 24 Apr 2019 00:06:38 +0300 [thread overview] Message-ID: <2d4cdbbf-0225-d04d-84ce-5e8b86ec3dcd@tarantool.org> (raw) In-Reply-To: <45E647F0-79F4-41DE-BD69-996A2D3EB7F1@tarantool.org> Hi! Thanks for the fixes! >>> diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c >>> index 6b38e8e66..d70b64c45 100644 >>> --- a/src/box/sql/expr.c >>> +++ b/src/box/sql/expr.c >>> @@ -3775,7 +3766,7 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target) >>> } >>> case TK_TRUE: >>> case TK_FALSE: { >>> - vdbe_emit_bool(pParse->pVdbe, pExpr, target); >>> + sqlVdbeAddOp2(v, OP_Bool, op == TK_TRUE, target); >>> return target; >>> } >>> >>>> 6. I see, that all other 'case's set pExpr->type. Why don't you >>>> do it here? >>> >>> It is required only for non-constant values. For literals it is assigned >>> in parse.y spanExpr(). >> >> 1. Then why case TK_INTEGER sets 'pExpr->type = FIELD_TYPE_INTEGER', >> TK_STRING sets 'pExpr->type = FIELD_TYPE_STRING;', TK_BLOB sets >> 'pExpr->type = FIELD_TYPE_SCALAR;' - I see all of them being set in >> parse.y. > > Those are literals, so as I said above, their types are assigned > right during parsing. If you are asking “why do we need to do so?”, > then answer is “they are leaf nodes and it is most appropriate > moment to do so”. No, my question was not about why they are set in parse.y, but why are they set in sqlExprCodeTarget() again, after parse.y. But I've just noticed, that the next patch "sql: improve type determination for column meta" fixes that. >>>> 8. Looking at all these type comparison prohibitions I am getting >>>> afraid of how will we select from SCALAR columns? >>>> >>>> A schema: >>>> >>>> box.execute('CREATE TABLE t (id INTEGER PRIMARY KEY, a SCALAR UNIQUE);') >>>> box.execute("INSERT INTO t VALUES (1, 1), (2, true), (3, false), (4, 'str')") >>>> >>>> SQL select: >>>> >>>>> box.execute('SELECT * FROM t WHERE a > 1') >>>> --- >>>> - error: 'Type mismatch: can not convert INTEGER to boolean' >>>> ... >>>> >>>> The same Lua select: >>>> >>>>> box.space.T.index[1]:select({1}, {iterator = 'GT'}) >>>> --- >>>> - - [4, 'str'] >>>> ... >>>> >>>> In fact, now we can not use SCALAR in SQL for any comparisons >>>> because it will raise type mismatch on literally everything. >>>> >>>> What are we going to do with it? IMO, we could add a flag like >>>> 'is_scalar' to struct Mem in its flags section, which would allow >>>> to compare this value with anything. >>> >>> Konstantin suggested to extend struct Mem with field_type, >>> which is going to substitute this flag. >>> >>>> Looks crutchy though. And is >>>> not a part of this issue of course, but should be filed into the >>>> issue list. >>>> >>>> I see a similar issue https://github.com/tarantool/tarantool/issues/4124. >>>> Probably, it is worth extending it instead of opening new. >>> >>> I consider this as a trade-off of using scalar: users shouldn’t use this >>> type until they are really have to. Nevertheless, they still can use CAST >>> operator and switch case, or write their own lua-function converting values >>> to required type. >> >> 2. Users may have good designed schema and work in each request with only >> one type in such a column, but still they will get errors just because >> the iterator can not walk to the needed tree node. Lets modify my example: >> >> SELECT * FROM t WHERE a = 1; >> >> This request implicitly says that it will work with numbers only, but >> somehow its success depends on the content of the space, not even >> related to '1' value. In a nutshell it means that insertion of something >> into a space can break existing requests not related to the inserted >> data. It is weird. Such scalar type would be useless. > > Yep, we can observe the same behaviour in DB2. For instance: DB2 is a perfect example when we deal with ANSI, but SCALAR is not ANSI and is not the same as VARCHAR. Its single and main purpose to be comparable with anything. If it can't be compared with anything, then it is not SCALAR. BTW, this VARCHAR case is also weird, even being the standard. What if I used "1" instead of simple 1? Please, consider these additions, on the branch: ====================================================================== diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index ef1a6a6bb..e0930f05d 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -2568,7 +2568,7 @@ case OP_IfNot: { /* jump, in1 */ if (pIn1->flags & MEM_Null) { c = pOp->p3; } else if ((pIn1->flags & MEM_Bool) != 0) { - c = pOp->opcode==OP_IfNot ? ! pIn1->u.b : pIn1->u.b; + c = pOp->opcode == OP_IfNot ? ! pIn1->u.b : pIn1->u.b; } else { double v; if (sqlVdbeRealValue(pIn1, &v) != 0) { diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c index 713a5c686..8c1aa4a8a 100644 --- a/src/box/sql/vdbemem.c +++ b/src/box/sql/vdbemem.c @@ -667,16 +667,14 @@ sqlVdbeMemCast(Mem * pMem, enum field_type type) return 0; case FIELD_TYPE_BOOLEAN: if ((pMem->flags & MEM_Int) != 0) { - pMem->u.b = pMem->u.i; - MemSetTypeFlag(pMem, MEM_Bool); + mem_set_bool(pMem, pMem->u.i); return 0; } if ((pMem->flags & MEM_Str) != 0) { bool value; if (str_cast_to_boolean(pMem->z, &value) != 0) return -1; - MemSetTypeFlag(pMem, MEM_Bool); - pMem->u.b = value; + mem_set_bool(pMem, value); return 0; } if ((pMem->flags & MEM_Bool) != 0)
next prev parent reply other threads:[~2019-04-23 21:06 UTC|newest] Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-04-14 15:03 [tarantool-patches] [PATCH 0/9] Introduce type BOOLEAN in SQL Nikita Pettik 2019-04-14 15:03 ` [tarantool-patches] [PATCH 1/9] sql: refactor mem_apply_numeric_type() Nikita Pettik 2019-04-14 15:04 ` [tarantool-patches] [PATCH 2/9] sql: disallow text values participate in sum() aggregate Nikita Pettik 2019-04-16 14:12 ` [tarantool-patches] " Vladislav Shpilevoy 2019-04-18 17:54 ` n.pettik 2019-04-22 18:02 ` Vladislav Shpilevoy 2019-04-23 19:58 ` n.pettik 2019-04-14 15:04 ` [tarantool-patches] [PATCH 3/9] sql: use msgpack types instead of custom ones Nikita Pettik 2019-04-16 14:12 ` [tarantool-patches] " Vladislav Shpilevoy 2019-04-18 17:54 ` n.pettik 2019-04-22 18:02 ` Vladislav Shpilevoy 2019-04-23 19:58 ` n.pettik 2019-04-14 15:04 ` [tarantool-patches] [PATCH 4/9] sql: introduce type boolean Nikita Pettik 2019-04-16 14:12 ` [tarantool-patches] " Vladislav Shpilevoy 2019-04-18 17:54 ` n.pettik 2019-04-22 18:02 ` Vladislav Shpilevoy 2019-04-23 19:58 ` n.pettik 2019-04-23 21:06 ` Vladislav Shpilevoy [this message] 2019-04-14 15:04 ` [tarantool-patches] [PATCH 5/9] sql: improve type determination for column meta Nikita Pettik 2019-04-16 14:12 ` [tarantool-patches] " Vladislav Shpilevoy 2019-04-18 17:54 ` n.pettik 2019-04-22 18:02 ` Vladislav Shpilevoy 2019-04-23 19:58 ` n.pettik 2019-04-14 15:04 ` [tarantool-patches] [PATCH 6/9] sql: make comparison predicate return boolean Nikita Pettik 2019-04-16 14:12 ` [tarantool-patches] " Vladislav Shpilevoy 2019-04-18 17:54 ` n.pettik 2019-04-14 15:04 ` [tarantool-patches] [PATCH 7/9] sql: make predicates accept and " Nikita Pettik 2019-04-16 14:12 ` [tarantool-patches] " Vladislav Shpilevoy 2019-04-18 17:55 ` n.pettik 2019-04-14 15:04 ` [tarantool-patches] [PATCH 9/9] sql: make <search condition> accept only boolean Nikita Pettik 2019-04-16 14:12 ` [tarantool-patches] " Vladislav Shpilevoy 2019-04-18 17:55 ` n.pettik 2019-04-22 18:02 ` Vladislav Shpilevoy 2019-04-23 19:59 ` n.pettik 2019-04-23 21:06 ` Vladislav Shpilevoy 2019-04-23 22:01 ` n.pettik [not found] ` <b2a84f129c2343d3da3311469cbb7b20488a21c2.1555252410.git.korablev@tarantool.org> 2019-04-16 14:12 ` [tarantool-patches] Re: [PATCH 8/9] sql: make LIKE predicate return boolean result Vladislav Shpilevoy 2019-04-18 17:55 ` n.pettik 2019-04-22 18:02 ` Vladislav Shpilevoy 2019-04-23 19:58 ` n.pettik 2019-04-24 10:28 ` [tarantool-patches] Re: [PATCH 0/9] Introduce type BOOLEAN in SQL Vladislav Shpilevoy 2019-04-25 8:46 ` Kirill Yukhin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=2d4cdbbf-0225-d04d-84ce-5e8b86ec3dcd@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='[tarantool-patches] Re: [PATCH 4/9] sql: introduce type boolean' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox