2014-04-21 17:36:54 +04:00
|
|
|
# 2014-04-21
|
2014-04-21 17:21:56 +04:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2014-04-21 17:36:54 +04:00
|
|
|
# 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.
|
|
|
|
#
|
2014-04-21 17:21:56 +04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-05-02 21:00:17 +03:00
|
|
|
set idxscan {SCAN TABLE t1 USING COVERING INDEX i1}
|
|
|
|
set tblscan {SCAN TABLE t1}
|
|
|
|
set grpsort {USE TEMP B-TREE FOR GROUP BY}
|
|
|
|
set sort {USE TEMP B-TREE FOR ORDER BY}
|
2014-04-21 17:21:56 +04: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-05-02 21:00:17 +03:00
|
|
|
{1 3 2 2 3 1} {$idxscan*$sort}
|
2014-04-21 17:21:56 +04:00
|
|
|
|
|
|
|
3 "SELECT * FROM t1 GROUP BY y, x ORDER BY y, x"
|
2018-05-02 21:00:17 +03:00
|
|
|
{3 1 2 2 1 3} {$idxscan*$sort}
|
2014-04-21 17:21:56 +04: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-05-02 21:00:17 +03:00
|
|
|
{3 1 2 2 1 3} {$tblscan*$grpsort}
|
2014-04-21 17:21:56 +04:00
|
|
|
|
|
|
|
6 "SELECT * FROM t1 GROUP BY y ORDER BY x"
|
2018-05-02 21:00:17 +03:00
|
|
|
{1 3 2 2 3 1} {$tblscan*$grpsort*$sort}
|
2014-04-21 17:21:56 +04:00
|
|
|
|
|
|
|
7 "SELECT * FROM t1 GROUP BY x, y ORDER BY x, y DESC"
|
2018-05-02 21:00:17 +03:00
|
|
|
{1 3 2 2 3 1} {$idxscan*$sort}
|
2014-04-21 17:21:56 +04:00
|
|
|
|
|
|
|
8 "SELECT * FROM t1 GROUP BY x, y ORDER BY x DESC, y DESC"
|
2019-09-21 18:44:12 +03:00
|
|
|
{3 1 2 2 1 3} {$idxscan}
|
2014-04-21 17:21:56 +04: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-05-02 21:00:17 +03:00
|
|
|
{1 3 2 2 3 1} {$idxscan*$sort}
|
2014-04-21 17:21:56 +04:00
|
|
|
|
|
|
|
}] {
|
|
|
|
do_execsql_test 1.$tn.1 $q $res
|
|
|
|
do_eqp_test 1.$tn.2 $q $eqp
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
finish_test
|