<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">ср, 18 июл. 2018 г. в 15:34, Nikita Tatunov <<a href="mailto:hollow653@gmail.com">hollow653@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello, Alexander! Please consider changes to the patch:<br><br><div class="gmail_quote"><div dir="ltr">вт, 17 июл. 2018 г. в 16:59, Alexander Turenko <<a href="mailto:alexander.turenko@tarantool.org" target="_blank">alexander.turenko@tarantool.org</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Nikita!<br>
<br>
Please, consider comments below.<br>
<br>
WBR, Alexander Turenko.<br>
<br>
On Mon, Jul 02, 2018 at 03:11:40PM +0300, N.Tatunov wrote:<br>
> To optimize the select-subquery tarantool uses<br>
> subquery flattening function which is only used<br>
> with respect to some restrictions. One of them<br>
> was implemented improperly.<br>
> <br>
<br>
Be certain: 'some restriction' and just 'improperly' are not good<br>
problem descriptions.<br>
<br>
I would use wording like the following.<br>
<br>
> When a subquery is a compound select the subquery flattening<br>
> optimization verify whether the ORDER BY clause presents, but only for<br>
> the last subquery component. The commit fixes that to verify all<br>
> subquery components.<br>
<br>
> In case of ORDER BY in non-last component of a compound select the<br>
> error should be raised. Accepting of such subqueries for the<br>
> flattening optimization prevents the error to be raised afterwards.<br>
> Instead it stuck into assertion violation inside flattenSubquery (see<br>
> the issue).<br>
<br></blockquote><div><br></div><div>Fixed:<br><br><div>To optimize the select-subquery tarantool uses</div><div>subquery flattening optimization which is only used</div><div>with respect to some restrictions. When any of</div><div>subselects but the last one has an ORDER BY</div><div>clause we should raise an error. So subquery</div><div>components containing it are not accepted</div><div>to be optimized.</div><div><br></div><div>Checking part was only checking if the last</div><div>subselect contains the clause which led to an</div><div>assertion fail. With the patch applied</div><div>flattening is not used in case any of</div><div>subselects has an ORDER BY.</div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I checked sqlite3 check-in 8000d230 (it is immediate predecessor of<br>
c9104b59 where the flattening optimization seems to be changed, but<br>
tarantool didn't updated with that check-in). It has the assert, but has<br>
no a change like yours, and correctly shows the following error:<br>
<br>
Error: ORDER BY clause should come after UNION ALL not before<br>
<br>
Why it is so?<br>
<br></blockquote></div></div></blockquote><div><br></div><div>I tried to test that problem on this sqlite3 version with -DSQLITE_DEBUG and assertion fails there. </div><div>Since flattening only makes another compound select-stmt with ORDER BY clause I guess error was</div><div>occuring on flattened version of it. Moreover in latter versions of sqlite3 this assert was deleted and the</div><div>restriction check wasn't fixed. So I assume sqlite3 developers just don't know about it or don't aim on</div><div>fixing it as the error anyways occurs but on flattened subquery.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +test:do_catchsql_test(<br>
> +     "subquery-9.3",<br>
> +     [[<br>
> +             SELECT * FROM (SELECT * FROM table1 ORDER BY 1 UNION All<br>
> +                               SELECT * FROM table1 UNION All<br>
> +                            SELECT * FROM table1);<br>
<br>
All -> ALL<br></blockquote><div><br>Also fixed. </div></div></div>
</blockquote></div></div>