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

A few simple test cases for the omit-unused-subquery-column optimization.

FossilOrigin-Name: cf8f57c53425d89619ece10edc197d7d28946d3b23fcb4f526330196c76d9cc1
This commit is contained in:
drh
2023-02-16 19:41:39 +00:00
parent 7defd20cb0
commit e43d101c83
3 changed files with 117 additions and 6 deletions

View File

@ -1,5 +1,5 @@
C Provide\san\soptimization-disable\smask\sfor\sthis\soptimization.\s\sDo\snot\sdo\sthe\noptimization\sif\sthe\ssubquery\sis\san\saggregate\sor\sis\sdistinct,\sbut\sallow\sit\sto\nbe\san\sephemeral\ssubquery.\s\sDo\snot\somit\scolumns\sthat\sare\sused\sin\sthe\sORDER\sBY\nof\sthe\ssubquery.
D 2023-02-16T18:04:49.549
C A\sfew\ssimple\stest\scases\sfor\sthe\somit-unused-subquery-column\soptimization.
D 2023-02-16T19:41:39.707
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -1462,6 +1462,7 @@ F test/selectD.test 6d1909b49970bf92f45ce657505befcef5fc7cbc13544e18103a316d3218
F test/selectE.test a8730ca330fcf40ace158f134f4fe0eb00c7edbf
F test/selectF.test 21c94e6438f76537b72532fa9fd4710cdd455fc3
F test/selectG.test 089f7d3d7e6db91566f00b036cb353107a2cca6220eb1cb264085a836dae8840
F test/selectH.test a1fed72a83a68ed858db6fcf6d8ddccc4a368645c0ef48dc3ac331d41efe34de
F test/session.test 78fa2365e93d3663a6e933f86e7afc395adf18be
F test/sessionfuzz-data1.db 1f8d5def831f19b1c74571037f0d53a588ea49a6c4ca2a028fc0c27ef896dbcb
F test/sessionfuzz.c 5eef09af01eeff6f20250ae4c0112c2e576e4d2f2026cc9a49dc5be6886fa6ee
@ -2045,8 +2046,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P cc148503db8ef180bce984328da7e84959afadd6a9613c2d03bc1eafeb95dfad
R 90e53b2f21c8456ed0ad4d26c75d661a
P 6b1a1f374d1372f11f5420d99645b218867100bf070bd3a8885bf5f00c189dff
R 1e3c678f9fbc9f1a9649605265913343
U drh
Z aa83be3d588d7cfee260c5a1a1ab587b
Z 7d95cef9a9f7a288c86a6fe2f6e032bb
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
6b1a1f374d1372f11f5420d99645b218867100bf070bd3a8885bf5f00c189dff
cf8f57c53425d89619ece10edc197d7d28946d3b23fcb4f526330196c76d9cc1

110
test/selectH.test Normal file
View File

@ -0,0 +1,110 @@
# 2023-02-16
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
# Test cases for the omit-unused-subquery-column optimization.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix selectH
do_execsql_test 1.1 {
CREATE TABLE t1(
c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
c10, c11, c12, c13, c14, c15, c16, c17, c18, c19,
c20, c21, c22, c23, c24, c25, c26, c27, c28, c29,
c30, c31, c32, c33, c34, c35, c36, c37, c38, c39,
c40, c41, c42, c43, c44, c45, c46, c47, c48, c49,
c50, c51, c52, c53, c54, c55, c56, c57, c58, c59,
c60, c61, c62, c63, c64, c65
);
INSERT INTO t1 VALUES(
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65
);
CREATE INDEX t1c60 ON t1(c60);
}
# The SQL counter(N) function adjusts the value of the global
# TCL variable ::selectH_cnt by the value N and returns the new
# value. By putting calls to counter(N) as unused columns in a
# view or subquery, we can check to see if the counter gets incremented,
# and if not that means that the unused column was omitted.
#
unset -nocomplain selectH_cnt
set selectH_cnt 0
proc selectH_counter {amt} {
global selectH_cnt
incr selectH_cnt $amt
return $selectH_cnt
}
db func counter selectH_counter
do_execsql_test 1.2 {
SELECT DISTINCT c44 FROM (
SELECT c0 AS a, *, counter(1) FROM t1
UNION ALL
SELECT c1 AS a, *, counter(1) FROM t1
) WHERE c60=60;
} {44}
do_test 1.3 {
set ::selectH_cnt
} {0}
do_execsql_test 2.1 {
SELECT a FROM (
SELECT counter(1) AS cnt, c15 AS a, *, c62 AS b FROM t1
UNION ALL
SELECT counter(1) AS cnt, c16 AS a, *, c61 AS b FROM t1
ORDER BY b
);
} {16 15}
do_test 2.2 {
set ::selectH_cnt
} {0}
do_execsql_test 3.1 {
CREATE VIEW v1 AS
SELECT c16 AS a, *, counter(1) AS x FROM t1
UNION ALL
SELECT c17 AS a, *, counter(1) AS x FROM t1
UNION ALL
SELECT c18 AS a, *, counter(1) AS x FROM t1
UNION ALL
SELECT c19 AS a, *, counter(1) AS x FROM t1;
SELECT count(*) FROM v1 WHERE c60=60;
} {4}
do_test 3.2 {
set ::selectH_cnt
} {0}
do_execsql_test 3.3 {
SELECT count(a) FROM v1 WHERE c60=60;
} {4}
do_execsql_test 3.4 {
SELECT a FROM v1 WHERE c60=60;
} {16 17 18 19}
do_test 3.5 {
set ::selectH_cnt
} {0}
do_execsql_test 3.6 {
SELECT x FROM v1 WHERE c60=60;
} {1 2 3 4}
do_test 3.7 {
set ::selectH_cnt
} {4}
finish_test