From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: tarantool-patches@freelists.org, "n.pettik" <korablev@tarantool.org> Subject: [tarantool-patches] Re: [PATCH 9/9] sql: make <search condition> accept only boolean Date: Wed, 24 Apr 2019 00:06:40 +0300 [thread overview] Message-ID: <4978b03d-c40e-ed4d-8aac-8567327779c3@tarantool.org> (raw) In-Reply-To: <09F94053-CCE0-49FD-8788-3F0749BF7ED8@tarantool.org> Thanks for the fixes! On 23/04/2019 22:59, n.pettik wrote: > >> On 18/04/2019 20:55, n.pettik wrote: >>> >>>>> <search condition> is a predicate used as a part of WHERE and >>>>> JOIN clauses. ANSI SQL states that <search condition> must >>>>> accept only boolean arguments. In our SQL it is implemented as >>>>> bytecode instruction OP_If which in turn carries out logic of >>>>> conditional jump. Since it can be involved in executing other routines >>>>> different from <search condition>, >>>> >>>> 1. Which other routines? What is a valid case of OP_If with non-boolean >>>> value in check? >>> >>> For instance, to verify that register containing LIMIT value is > 0. >> >> Yes, and this is almost the only case. What is more, it happens only once >> per request, to check if LIMIT == 0 initially. Further it is decremented >> and checked via OP_IfNotZero and OP_DecrJumpZero. >> >>> It is quite hard to track values which come to this opcode, so we >>> can’t be sure that it always accepts booleans. >> >> It is hard, but without it >> >> 1) You can't be sure, that really all the search conditions >> are checked to be booleans; >> >> 2) It makes OP_If/IfNot slower, and they are called repeatedly in >> requests; > > One branching worth nothing. Below you suggest to split opcode > into two (fix me if I’m wrong), which in turn affects performance way much more. The places which I proposed to split are called only once per request. For example, OP_IfNot with iLimit was used for initial check that it is not zero. All the next work with iLimit was being done via special opcodes OP_DecrJumpZero and OP_IfNotZero. On the other hand, if we branch inside OP_IfNot, we branch repeatedly, in cycles, many times per request. > >> 3) It adds one more flag SQL_BOOLREQ, which looks very crutchy. > > IMHO it is matter of taste. Anyway, removed this flag. You are right, it would have been, if OP_IfNot/OP_If had already had some other flags. But you proposed to change the opcodes dramatically, to add a new argument just for some minor cases. And as a result it hid a bug with CASE-WHEN search condition. >> It violates the standard. "Information technology — >> Database languages — SQL — Part 2: Foundation (SQL/Foundation)", >> 2011, page 230. >> >> 'WHEN' is a search condition, but I've used '1', not 'true'. >> Also I tested it on PostgreSQL - they raise an error, so it is >> both standard and practically used way. >> >> Below are my fixes for LIMIT and a small obvious refactoring, >> but they are *not on the branch* - not all the tests pass when I >> start banning non-bools in OP_If/IfNot. > > I’ve fixed that. But you still set OPFLAG_BOOLREQ and SQL_BOOLREQ. Why? Also the commit message still describes this flag as a key change of the patch.
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 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 [this message] 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=4978b03d-c40e-ed4d-8aac-8567327779c3@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='[tarantool-patches] Re: [PATCH 9/9] sql: make <search condition> accept only 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