1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

When translating arguments of aggregate functions into references to

expression indexes, make sure to only translate them for the current
aggregate when there are nested aggregates.
[forum/forumpost/409ebc7368|Forum post 409ebc7368].

FossilOrigin-Name: 898bfa1afd8260eaaf2aa6db94e74d99ebf4e8a6dc02cf21d20cd981393609a5
This commit is contained in:
drh
2023-04-03 23:49:00 +00:00
parent f61bf3dbe8
commit 39b07f1afc
5 changed files with 32 additions and 12 deletions

View File

@ -410,4 +410,19 @@ do_execsql_test 10.1 {
GROUP BY SUBSTR(0,0);
} 4
# 2023-04-03 https://sqlite.org/forum/forumpost/409ebc7368
# When a generated column appears in both an outer and an inner loop
# (that is to say, the same table is used in both loops) and the
# generated column is indexed and it is used inside an aggregate function,
# make sure that the terms resolve to the correct aggregate.
#
do_execsql_test 11.0 {
CREATE TABLE t3 (a INT, b AS (-a));
CREATE INDEX t3x ON t3(b, a);
INSERT INTO t3(a) VALUES(44);
SELECT * FROM t3 AS a0
WHERE (SELECT sum(-a0.a=b) FROM t3 GROUP BY b)
GROUP BY b;
} {44 -44}
finish_test