SQLite

Check-in [523b4237]
Login

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

Overview
Comment:Fix the query flattener optimization so that it preserve the "SF_Compound" bit when flattening a compound subquery into a non-compound outer query. Failure to preserve that bit could allow subsequent flattenings which are not valid. Fix for ticket [c41afac34f15781fe09cd].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 523b42371122d9e1b3185425745f1490138bff7f7cc941ee26ee81df7ade5bf4
User & Date: drh 2019-05-29 17:22:38
References
2019-05-29
18:33
Add an assert() as an additional test for fix in check-in [523b42371122d9e1b3]. (check-in: f9e85e6c user: drh tags: trunk)
Context
2019-05-29
18:33
Add an assert() as an additional test for fix in check-in [523b42371122d9e1b3]. (check-in: f9e85e6c user: drh tags: trunk)
17:22
Fix the query flattener optimization so that it preserve the "SF_Compound" bit when flattening a compound subquery into a non-compound outer query. Failure to preserve that bit could allow subsequent flattenings which are not valid. Fix for ticket [c41afac34f15781fe09cd]. (check-in: 523b4237 user: drh tags: trunk)
2019-05-28
14:42
Fix an assert() in fts3 that could fail when processing corrupt records. Also some minor sanitizer warnings. (check-in: c736c40a user: dan tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/select.c.

4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051

4052
4053
4054
4055
4056
4057
4058
      x.iTable = iParent;
      x.iNewTable = iNewParent;
      x.isLeftJoin = isLeftJoin;
      x.pEList = pSub->pEList;
      substSelect(&x, pParent, 0);
    }
  
    /* The flattened query is distinct if either the inner or the
    ** outer query is distinct. 
    */
    pParent->selFlags |= pSub->selFlags & SF_Distinct;

  
    /*
    ** SELECT ... FROM (SELECT ... LIMIT a OFFSET b) LIMIT x OFFSET y;
    **
    ** One is tempted to try to add a and b to combine the limits.  But this
    ** does not work if either limit is negative.
    */







|
|
<
|
>







4041
4042
4043
4044
4045
4046
4047
4048
4049

4050
4051
4052
4053
4054
4055
4056
4057
4058
      x.iTable = iParent;
      x.iNewTable = iNewParent;
      x.isLeftJoin = isLeftJoin;
      x.pEList = pSub->pEList;
      substSelect(&x, pParent, 0);
    }
  
    /* The flattened query is a compound if either the inner or the
    ** outer query is a compound. */

    pParent->selFlags |= pSub->selFlags & SF_Compound;
    assert( (pSub->selFlags & SF_Distinct)==0 ); /* restriction (17b) */
  
    /*
    ** SELECT ... FROM (SELECT ... LIMIT a OFFSET b) LIMIT x OFFSET y;
    **
    ** One is tempted to try to add a and b to combine the limits.  But this
    ** does not work if either limit is negative.
    */

Changes to test/select6.test.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing SELECT statements that contain
# subqueries in their FROM clause.
#
# $Id: select6.test,v 1.29 2009/01/09 01:12:28 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Omit this whole file if the library is build without subquery support.
ifcapable !subquery {
  finish_test







<







8
9
10
11
12
13
14

15
16
17
18
19
20
21
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing SELECT statements that contain
# subqueries in their FROM clause.
#


set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Omit this whole file if the library is build without subquery support.
ifcapable !subquery {
  finish_test
609
610
611
612
613
614
615


616














617
  DROP TABLE t2;
  CREATE TABLE t1(x);
  CREATE TABLE t2(y, z);
  SELECT ( SELECT y FROM t2 WHERE z = cnt )
    FROM ( SELECT count(*) AS cnt FROM t1 );
} {{}}


















finish_test







>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>

608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
  DROP TABLE t2;
  CREATE TABLE t1(x);
  CREATE TABLE t2(y, z);
  SELECT ( SELECT y FROM t2 WHERE z = cnt )
    FROM ( SELECT count(*) AS cnt FROM t1 );
} {{}}

# 2019-05-29 ticket https://www.sqlite.org/src/info/c41afac34f15781f
# A LIMIT clause in a subquery is incorrectly applied to a subquery.
#
do_execsql_test 12.100 {
  DROP TABLE t1;
  DROP TABLE t2;
  CREATE TABLE t1(a);
  INSERT INTO t1 VALUES(1);
  INSERT INTO t1 VALUES(2);
  CREATE TABLE t2(b);
  INSERT INTO t2 VALUES(3);
  SELECT * FROM (
    SELECT * FROM (SELECT * FROM t1 LIMIT 1)
    UNION ALL
    SELECT * from t2);
} {1 3}

finish_test