sqlcipher/test/tkt-b75a9ca6b0.test

78 lines
2.0 KiB
Plaintext
Raw Permalink Normal View History

2014-09-30 08:40:45 -05:00
# 2014-04-21
#
# 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 that ticket [b75a9ca6b0] has been fixed.
#
# Ticket [b75a9ca6b0] concerns queries that have both a GROUP BY
# and an ORDER BY. This code verifies that SQLite is able to
# optimize out the ORDER BY in some circumstances, but retains the
# ORDER BY when necessary.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix tkt-b75a9ca6b0
do_execsql_test 1 {
CREATE TABLE t1 (x, y);
INSERT INTO t1 VALUES (1, 3);
INSERT INTO t1 VALUES (2, 2);
INSERT INTO t1 VALUES (3, 1);
}
do_execsql_test 1.1 {
CREATE INDEX i1 ON t1(x, y);
}
2021-10-05 16:25:47 -04:00
set idxscan {SCAN t1 USING COVERING INDEX i1}
set tblscan {SCAN t1}
2018-09-18 12:31:37 -04:00
set grpsort {USE TEMP B-TREE FOR GROUP BY}
set sort {USE TEMP B-TREE FOR ORDER BY}
2014-09-30 08:40:45 -05:00
foreach {tn q res eqp} [subst -nocommands {
1 "SELECT * FROM t1 GROUP BY x, y ORDER BY x,y"
{1 3 2 2 3 1} {$idxscan}
2 "SELECT * FROM t1 GROUP BY x, y ORDER BY x"
2018-09-18 12:31:37 -04:00
{1 3 2 2 3 1} {$idxscan*$sort}
2014-09-30 08:40:45 -05:00
3 "SELECT * FROM t1 GROUP BY y, x ORDER BY y, x"
2018-09-18 12:31:37 -04:00
{3 1 2 2 1 3} {$idxscan*$sort}
2014-09-30 08:40:45 -05:00
4 "SELECT * FROM t1 GROUP BY x ORDER BY x"
{1 3 2 2 3 1} {$idxscan}
5 "SELECT * FROM t1 GROUP BY y ORDER BY y"
2018-09-18 12:31:37 -04:00
{3 1 2 2 1 3} {$tblscan*$grpsort}
2014-09-30 08:40:45 -05:00
6 "SELECT * FROM t1 GROUP BY y ORDER BY x"
2018-09-18 12:31:37 -04:00
{1 3 2 2 3 1} {$tblscan*$grpsort*$sort}
2014-09-30 08:40:45 -05:00
7 "SELECT * FROM t1 GROUP BY x, y ORDER BY x, y DESC"
2018-09-18 12:31:37 -04:00
{1 3 2 2 3 1} {$idxscan*$sort}
2014-09-30 08:40:45 -05:00
8 "SELECT * FROM t1 GROUP BY x, y ORDER BY x DESC, y DESC"
2019-10-27 18:21:41 -04:00
{3 1 2 2 1 3} {$idxscan}
2014-09-30 08:40:45 -05:00
9 "SELECT * FROM t1 GROUP BY x, y ORDER BY x ASC, y ASC"
{1 3 2 2 3 1} {$idxscan}
10 "SELECT * FROM t1 GROUP BY x, y ORDER BY x COLLATE nocase, y"
2018-09-18 12:31:37 -04:00
{1 3 2 2 3 1} {$idxscan*$sort}
2014-09-30 08:40:45 -05:00
}] {
do_execsql_test 1.$tn.1 $q $res
do_eqp_test 1.$tn.2 $q $eqp
}
finish_test