/ Check-in [c403502c]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix handling of queries with VALUES on the left and UNION ALL SELECT on the right and a LIMIT clause.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c403502cdce8b82e570e6fc49ab7f5144800c189
User & Date: drh 2015-05-20 00:15:27
Context
2015-05-20
17:36
Fix the initialization logic in CREATE TABLE AS so that the correct affinities are applied to all values being inserted into the new table, even if the RHS is a compound SELECT. Fix for ticket [f2ad7de056ab1dc9200]. check-in: 6a0cf3ce user: drh tags: trunk
15:51
A proposed fix for the problem of CREATE TABLE AS generating a table that has INTEGER values in a TEXT column. Ticket [f2ad7de056ab1dc92]. check-in: d5e2c1fc user: drh tags: create-table-as-type-fix
00:15
Fix handling of queries with VALUES on the left and UNION ALL SELECT on the right and a LIMIT clause. check-in: c403502c user: drh tags: trunk
2015-05-19
23:56
Enhance the selecttrace display by showing Select.selFlags. check-in: 45d3893c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/parse.y.

   444    444     A = p;
   445    445   }
   446    446   
   447    447   selectnowith(A) ::= oneselect(X).                      {A = X;}
   448    448   %ifndef SQLITE_OMIT_COMPOUND_SELECT
   449    449   selectnowith(A) ::= selectnowith(X) multiselect_op(Y) oneselect(Z).  {
   450    450     Select *pRhs = Z;
          451  +  Select *pLhs = X;
   451    452     if( pRhs && pRhs->pPrior ){
   452    453       SrcList *pFrom;
   453    454       Token x;
   454    455       x.n = 0;
   455    456       parserDoubleLinkSelect(pParse, pRhs);
   456    457       pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
   457    458       pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0);
   458    459     }
   459    460     if( pRhs ){
   460    461       pRhs->op = (u8)Y;
   461         -    pRhs->pPrior = X;
          462  +    pRhs->pPrior = pLhs;
          463  +    if( ALWAYS(pLhs) ) pLhs->selFlags &= ~SF_MultiValue;
   462    464       pRhs->selFlags &= ~SF_MultiValue;
   463    465       if( Y!=TK_ALL ) pParse->hasCompound = 1;
   464    466     }else{
   465         -    sqlite3SelectDelete(pParse->db, X);
          467  +    sqlite3SelectDelete(pParse->db, pLhs);
   466    468     }
   467    469     A = pRhs;
   468    470   }
   469    471   %type multiselect_op {int}
   470    472   multiselect_op(A) ::= UNION(OP).             {A = @OP;}
   471    473   multiselect_op(A) ::= UNION ALL.             {A = TK_ALL;}
   472    474   multiselect_op(A) ::= EXCEPT|INTERSECT(OP).  {A = @OP;}

Changes to test/select4.test.

   905    905   } {1 3}
   906    906   do_execsql_test select4-14.14 {
   907    907     VALUES(1),(2),(3) EXCEPT VALUES(1),(3);
   908    908   } {2}
   909    909   do_execsql_test select4-14.15 {
   910    910     SELECT * FROM (SELECT 123), (SELECT 456) ON likely(0 OR 1) OR 0;
   911    911   } {123 456}
          912  +do_execsql_test select4-14.16 {
          913  +  VALUES(1),(2),(3),(4) UNION ALL SELECT 5 LIMIT 99;
          914  +} {1 2 3 4 5}
          915  +do_execsql_test select4-14.17 {
          916  +  VALUES(1),(2),(3),(4) UNION ALL SELECT 5 LIMIT 3;
          917  +} {1 2 3}
   912    918   
   913    919   finish_test