SQLite

Check-in [76b90f26]
Login

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

Overview
Comment:Fix the handling of indexed expressions in an outer query that appear as corelated values inside an aggregate function within a subquery.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | branch-3.41
Files: files | file ages | folders
SHA3-256: 76b90f267c5cc676d9ba97caa0f664e75af8b21c8eb574ec0c1f11e4deedb49e
User & Date: drh 2023-03-24 20:39:13
Context
2023-03-24
20:41
Increase the version number to 3.41.3. (check-in: 9a19c6ce user: drh tags: branch-3.41)
20:39
Fix the handling of indexed expressions in an outer query that appear as corelated values inside an aggregate function within a subquery. (check-in: 76b90f26 user: drh tags: branch-3.41)
20:35
Fix the handling of indexed expressions in an outer query that appear as corelated values inside an aggregate function within a subquery. Forum post 79cf371080. (check-in: d8259877 user: drh tags: trunk)
17:01
Fix byte-code register allocation in ANALYZE for STAT4 when there multiple indexes with differing numbers of columns. (check-in: 13c8c60b user: drh tags: branch-3.41)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/select.c.

6419
6420
6421
6422
6423
6424
6425

6426
6427
6428
6429
6430
6431
6432
6433
  struct AggInfo_col *pCol;
  UNUSED_PARAMETER(pWalker);
  if( pExpr->pAggInfo==0 ) return WRC_Continue;
  if( pExpr->op==TK_AGG_COLUMN ) return WRC_Continue;
  if( pExpr->op==TK_AGG_FUNCTION ) return WRC_Continue;
  if( pExpr->op==TK_IF_NULL_ROW ) return WRC_Continue;
  pAggInfo = pExpr->pAggInfo;

  assert( pExpr->iAgg>=0 && pExpr->iAgg<pAggInfo->nColumn );
  pCol = &pAggInfo->aCol[pExpr->iAgg];
  pExpr->op = TK_AGG_COLUMN;
  pExpr->iTable = pCol->iTable;
  pExpr->iColumn = pCol->iColumn;
  return WRC_Prune;
}








>
|







6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
  struct AggInfo_col *pCol;
  UNUSED_PARAMETER(pWalker);
  if( pExpr->pAggInfo==0 ) return WRC_Continue;
  if( pExpr->op==TK_AGG_COLUMN ) return WRC_Continue;
  if( pExpr->op==TK_AGG_FUNCTION ) return WRC_Continue;
  if( pExpr->op==TK_IF_NULL_ROW ) return WRC_Continue;
  pAggInfo = pExpr->pAggInfo;
  if( pExpr->iAgg>=pAggInfo->nColumn ) return WRC_Continue;
  assert( pExpr->iAgg>=0 );
  pCol = &pAggInfo->aCol[pExpr->iAgg];
  pExpr->op = TK_AGG_COLUMN;
  pExpr->iTable = pCol->iTable;
  pExpr->iColumn = pCol->iColumn;
  return WRC_Prune;
}

Changes to test/indexexpr2.test.

367
368
369
370
371
372
373














374
375
    SELECT * FROM t1 LEFT JOIN t2 WHERE $expr
  " {1 2 {} {} 3 4 {} {}}

  do_execsql_test 8.5.$tn.2 "
    SELECT ($expr) IS TRUE FROM t1 LEFT JOIN t2
  " {1 1}
}















finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>


367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
    SELECT * FROM t1 LEFT JOIN t2 WHERE $expr
  " {1 2 {} {} 3 4 {} {}}

  do_execsql_test 8.5.$tn.2 "
    SELECT ($expr) IS TRUE FROM t1 LEFT JOIN t2
  " {1 1}
}

# 2023-03-24 https://sqlite.org/forum/forumpost/79cf371080
#
reset_db
do_execsql_test 9.0 {
  CREATE TABLE t1(a INT, b INT);
  CREATE INDEX t1x ON t1(a, abs(b));
  CREATE TABLE t2(c INT, d INT);
  INSERT INTO t1(a,b) VALUES(4,4),(5,-5),(5,20),(6,6);
  INSERT INTO t2(c,d) VALUES(100,1),(200,1),(300,2);
  SELECT *,
    (SELECT max(c+abs(b)) FROM t2 GROUP BY d ORDER BY d LIMIT 1) AS subq
   FROM t1 WHERE a=5;
} {5 -5 205 5 20 220}

finish_test