<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">ср, 18 июл. 2018 г. в 23:36, n.pettik <<a href="mailto:korablev@tarantool.org">korablev@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"><br>
> diff --git a/src/box/sql/select.c b/src/box/sql/select.c<br>
> index 54f78a9..c035691 100644<br>
> --- a/src/box/sql/select.c<br>
> +++ b/src/box/sql/select.c<br>
> @@ -3893,14 +3893,14 @@ flattenSubquery(Parse * pParse,               /* Parsing context */<br>
>        * queries.<br>
>        */<br>
>       if (pSub->pPrior) {<br>
> -             if (pSub->pOrderBy) {<br>
> -                     return 0;       /* Restriction 20 */<br>
> -             }<br>
>               if (isAgg || (p->selFlags & SF_Distinct) != 0<br>
>                   || pSrc->nSrc != 1) {<br>
>                       return 0;<br>
>               }<br>
>               for (pSub1 = pSub; pSub1; pSub1 = pSub1->pPrior) {<br>
> +                     if (pSub1->pOrderBy) {<br>
> +                             return 0;       /* Restriction 20 */<br>
> +                     }<br>
<br>
According to our code style:<br>
- use explicit != NULL comparison;<br>
- don’t put bracers around one-line if statement;<br>
- put comment above the code to be commented;<br>
<br></blockquote><div><br></div><div>Fixed.</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">
>diff --git a/test/sql-tap/subquery.test.lua b/test/sql-tap/subquery.test.lua<br>
>--- a/test/sql-tap/subquery.test.lua<br>
>+++ b/test/sql-tap/subquery.test.lua<br>
>+test:do_execsql_test(<br>
>+       "subquery-9.2",<br>
>+       [[<br>
>+               SELECT 'abc' FROM (SELECT * FROM table1 UNION ALL<br>
>+                                   SELECT * FROM table1 UNION ALL<br>
>+                                  SELECT * FROM table1 ORDER BY 1);<br>
>+       ]], {<br>
>+               -- <subquery-9.2><br>
>+               'abc','abc','abc','abc','abc','abc'<br>
>+               -- <subquery-9.2><br>
>+       })<br>
<br>
Why did you use here SELECT ‘abc’ and in other tests - SELECT *?<br>
It is nitpicking, but just tests look a little weird..</blockquote><div><br></div><div>Yes, kind of weird. Why not though?</div><div>Fixed, anyways.</div><div><br></div><div>Diff:<br><br><div>diff --git a/src/box/sql/select.c b/src/box/sql/select.c</div><div>index 54f78a9..1a6b034 100644</div><div>--- a/src/box/sql/select.c</div><div>+++ b/src/box/sql/select.c</div><div>@@ -3893,14 +3893,14 @@ flattenSubquery(Parse * pParse,<span style="white-space:pre">            </span>/* Parsing context */</div><div> <span style="white-space:pre">       </span> * queries.</div><div> <span style="white-space:pre"> </span> */</div><div> <span style="white-space:pre"> </span>if (pSub->pPrior) {</div><div>-<span style="white-space:pre">               </span>if (pSub->pOrderBy) {</div><div>-<span style="white-space:pre">                     </span>return 0;<span style="white-space:pre">    </span>/* Restriction 20 */</div><div>-<span style="white-space:pre">         </span>}</div><div> <span style="white-space:pre">           </span>if (isAgg || (p->selFlags & SF_Distinct) != 0</div><div> <span style="white-space:pre">                </span>    || pSrc->nSrc != 1) {</div><div> <span style="white-space:pre">                      </span>return 0;</div><div> <span style="white-space:pre">           </span>}</div><div> <span style="white-space:pre">           </span>for (pSub1 = pSub; pSub1; pSub1 = pSub1->pPrior) {</div><div>+<span style="white-space:pre">                        </span>/* Restriction 20 */</div><div>+<span style="white-space:pre">                 </span>if (pSub1->pOrderBy != NULL)</div><div>+<span style="white-space:pre">                              </span>return 0;</div><div> <span style="white-space:pre">                   </span>testcase((pSub1-></div><div> <span style="white-space:pre">                                </span>  selFlags & (SF_Distinct | SF_Aggregate)) ==</div><div> <span style="white-space:pre">                          </span> SF_Distinct);</div><div>diff --git a/test/sql-tap/subquery.test.lua b/test/sql-tap/subquery.test.lua</div><div>index 06631c1..8fde62d 100755</div><div>--- a/test/sql-tap/subquery.test.lua</div><div>+++ b/test/sql-tap/subquery.test.lua</div><div>@@ -1,6 +1,6 @@</div><div> #!/usr/bin/env tarantool</div><div> test = require("sqltester")</div><div>-test:plan(69)</div><div>+test:plan(73)</div><div> </div><div> --!./tcltestrunner.lua</div><div> -- 2005 January 19</div><div>@@ -926,6 +926,52 @@ test:do_execsql_test(</div><div>         -- </subquery-8.1></div><div>     })</div><div> </div><div>+test:do_catchsql_test(</div><div>+<span style="white-space:pre">  </span>"subquery-9.0",</div><div>+<span style="white-space:pre">    </span>[[</div><div>+<span style="white-space:pre">           </span>DROP TABLE IF EXISTS table1;</div><div>+<span style="white-space:pre">         </span>CREATE TABLE table1 (id VARCHAR(100) PRIMARY KEY);</div><div>+<span style="white-space:pre">           </span>INSERT INTO table1 VALUES ('abc'), ('abd');</div><div>+<span style="white-space:pre">  </span>]], {</div><div>+<span style="white-space:pre">                </span>-- <subquery-9.0></div><div>+<span style="white-space:pre">              </span>0</div><div>+<span style="white-space:pre">            </span>-- <subquery-9.0></div><div>+<span style="white-space:pre">      </span>})</div><div>+</div><div>+test:do_catchsql_test(</div><div>+<span style="white-space:pre">     </span>"subquery-9.1",</div><div>+<span style="white-space:pre">    </span>[[</div><div>+<span style="white-space:pre">           </span>SELECT * FROM (SELECT * FROM table1 UNION ALL</div><div>+                               SELECT * FROM table1 ORDER BY 1 UNION ALL</div><div>+<span style="white-space:pre">                        </span>       SELECT * FROM table1);</div><div>+<span style="white-space:pre">    </span>]], {</div><div>+<span style="white-space:pre">                </span>-- <subquery-9.1></div><div>+<span style="white-space:pre">              </span>1, 'ORDER BY clause should come after UNION ALL not before'</div><div>+<span style="white-space:pre">          </span>-- <subquery-9.1></div><div>+<span style="white-space:pre">      </span>})</div><div>+</div><div>+test:do_execsql_test(</div><div>+<span style="white-space:pre">      </span>"subquery-9.2",</div><div>+<span style="white-space:pre">    </span>[[</div><div>+<span style="white-space:pre">           </span>SELECT * FROM (SELECT * FROM table1 UNION ALL</div><div>+                                   SELECT * FROM table1 UNION ALL</div><div>+<span style="white-space:pre">                             </span>   SELECT * FROM table1 ORDER BY 1);</div><div>+<span style="white-space:pre">       </span>]], {</div><div>+<span style="white-space:pre">                </span>-- <subquery-9.2></div><div>+<span style="white-space:pre">              </span>'abc', 'abc', 'abc', 'abd', 'abd', 'abd'</div><div>+<span style="white-space:pre">             </span>-- <subquery-9.2></div><div>+<span style="white-space:pre">      </span>})</div><div> </div><div>+test:do_catchsql_test(</div><div>+<span style="white-space:pre">    </span>"subquery-9.3",</div><div>+<span style="white-space:pre">    </span>[[</div><div>+<span style="white-space:pre">           </span>SELECT * FROM (SELECT * FROM table1 ORDER BY 1 UNION ALL</div><div>+                               SELECT * FROM table1 UNION ALL</div><div>+<span style="white-space:pre">                        </span>       SELECT * FROM table1);</div><div>+<span style="white-space:pre">    </span>]], {</div><div>+             -- <subquery-9.3></div><div>+             1, 'ORDER BY clause should come after UNION ALL not before'</div><div>+             -- <subquery-9.3></div><div>+<span style="white-space:pre">   </span>})</div><div> </div><div> test:finish_test()</div></div><div><br></div></div></div>