SQLite

Check-in [3f45007d]
Login

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

Overview
Comment:Fix the query flattener to deal with a RIGHT JOIN corner case described by forum post 323f86cc30.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3f45007d544e5f787d5837b4d9f484ba473d69cdba83c229228e9c2f6b972b75
User & Date: drh 2022-06-07 13:09:58
References
2022-06-08
13:13
New test cases refute check-in [3f45007d544e5f78]. (check-in: 12d3c96c user: drh tags: right-join-query-flattener)
Context
2022-06-08
13:13
New test cases refute check-in [3f45007d544e5f78]. (check-in: 12d3c96c user: drh tags: right-join-query-flattener)
12:20
Update the routine that determines whether or not a partial index can be used so that it is not specific to LEFT JOIN. (check-in: 5a107fd7 user: drh tags: trunk)
2022-06-07
13:09
Fix the query flattener to deal with a RIGHT JOIN corner case described by forum post 323f86cc30. (check-in: 3f45007d user: drh tags: trunk)
11:02
Test cases for forum post 323f86cc30 added to join8.test, though commented out so that they do not (yet) run. (check-in: 7f97cb67 user: drh tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/select.c.

3759
3760
3761
3762
3763
3764
3765
3766
3767
3768

3769
3770
3771
3772
3773
3774
3775
** of the subquery rather the result set of the subquery.
*/
static Expr *substExpr(
  SubstContext *pSubst,  /* Description of the substitution */
  Expr *pExpr            /* Expr in which substitution occurs */
){
  if( pExpr==0 ) return 0;
  if( ExprHasProperty(pExpr, EP_OuterON)
   && pExpr->w.iJoin==pSubst->iTable
  ){

    pExpr->w.iJoin = pSubst->iNewTable;
  }
  if( pExpr->op==TK_COLUMN
   && pExpr->iTable==pSubst->iTable
   && !ExprHasProperty(pExpr, EP_FixedCol)
  ){
#ifdef SQLITE_ALLOW_ROWID_IN_VIEW







|


>







3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
** of the subquery rather the result set of the subquery.
*/
static Expr *substExpr(
  SubstContext *pSubst,  /* Description of the substitution */
  Expr *pExpr            /* Expr in which substitution occurs */
){
  if( pExpr==0 ) return 0;
  if( ExprHasProperty(pExpr, EP_OuterON|EP_InnerON)
   && pExpr->w.iJoin==pSubst->iTable
  ){
    testcase( ExprHasProperty(pExpr, EP_InnerON) );
    pExpr->w.iJoin = pSubst->iNewTable;
  }
  if( pExpr->op==TK_COLUMN
   && pExpr->iTable==pSubst->iTable
   && !ExprHasProperty(pExpr, EP_FixedCol)
  ){
#ifdef SQLITE_ALLOW_ROWID_IN_VIEW

Changes to test/join8.test.

622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
  CREATE INDEX t2b ON t2( (b IS NOT NULL) );
}

do_execsql_test join8-19010 {
  SELECT * FROM t1 LEFT JOIN t2 ON true INNER JOIN t3 ON (b IS NOT NULL)=0;
}

if 0 {
# 2022-06-07
# https://sqlite.org/forum/forumpost/323f86cc30
reset_db
do_execsql_test join8-20000 {
  CREATE TABLE t1(x TEXT);
  INSERT INTO t1(x) VALUES('aaa');
  CREATE VIEW v0(y) AS SELECT x FROM t1;







<







622
623
624
625
626
627
628

629
630
631
632
633
634
635
  CREATE INDEX t2b ON t2( (b IS NOT NULL) );
}

do_execsql_test join8-19010 {
  SELECT * FROM t1 LEFT JOIN t2 ON true INNER JOIN t3 ON (b IS NOT NULL)=0;
}


# 2022-06-07
# https://sqlite.org/forum/forumpost/323f86cc30
reset_db
do_execsql_test join8-20000 {
  CREATE TABLE t1(x TEXT);
  INSERT INTO t1(x) VALUES('aaa');
  CREATE VIEW v0(y) AS SELECT x FROM t1;
653
654
655
656
657
658
659
660
661
662
  SELECT count(*)
    FROM (SELECT 99 as "m" FROM t2 JOIN v0 ON z<>'' RIGHT JOIN t1 ON z<>'') AS "t3";
} {1}
do_execsql_test join8-20060 {
  SELECT count(*) 
    FROM (SELECT 99 as "m" FROM t2 JOIN v0 ON z<>'' RIGHT JOIN t1 ON z<>'' ORDER BY z) AS "t3";
} {1}
}

finish_test







|
<

652
653
654
655
656
657
658
659

660
  SELECT count(*)
    FROM (SELECT 99 as "m" FROM t2 JOIN v0 ON z<>'' RIGHT JOIN t1 ON z<>'') AS "t3";
} {1}
do_execsql_test join8-20060 {
  SELECT count(*) 
    FROM (SELECT 99 as "m" FROM t2 JOIN v0 ON z<>'' RIGHT JOIN t1 ON z<>'' ORDER BY z) AS "t3";
} {1}


finish_test