mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Add initial infrastructure for cursors. In where.c, optimize out clauses
of the form "ORDER BY rowid" if a table scan is being performed. Do a reverse table scan if "ORDER BY rowid DESC" is present. (CVS 2141) FossilOrigin-Name: fc8c1393c86017a816beb52725b68af3b973f979
This commit is contained in:
@ -1,14 +1,17 @@
|
||||
# 2004 November 10
|
||||
#
|
||||
# The author or author's hereby grant to the public domain a non-exclusive,
|
||||
# fully paid-up, perpetual, license in the software and all related
|
||||
# intellectual property to make, have made, use, have used, reproduce,
|
||||
# prepare derivative works, distribute, perform and display the work.
|
||||
# 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.
|
||||
#
|
||||
#*************************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is testing the ALTER TABLE statement.
|
||||
#
|
||||
# $Id: alter.test,v 1.7 2004/11/22 13:35:42 danielk1977 Exp $
|
||||
# $Id: alter.test,v 1.8 2004/11/22 19:12:21 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
|
@ -12,7 +12,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is page cache subsystem.
|
||||
#
|
||||
# $Id: collate4.test,v 1.4 2004/11/03 16:27:02 drh Exp $
|
||||
# $Id: collate4.test,v 1.5 2004/11/22 19:12:21 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@ -669,6 +669,7 @@ do_test collate4-4.15 {
|
||||
# These indices are never used for sorting in SQLite. And you can't
|
||||
# create another index on an INTEGER PRIMARY KEY column, so we don't have
|
||||
# to test that.
|
||||
# (Revised 2004-Nov-22): The ROWID can be used for sorting now.
|
||||
#
|
||||
do_test collate4-6.0 {
|
||||
execsql {
|
||||
@ -682,12 +683,12 @@ do_test collate4-6.1 {
|
||||
cksort {
|
||||
SELECT * FROM collate4t1 ORDER BY 1;
|
||||
}
|
||||
} {10 15 101 sort}
|
||||
} {10 15 101 nosort}
|
||||
do_test collate4-6.2 {
|
||||
cksort {
|
||||
SELECT * FROM collate4t1 ORDER BY oid;
|
||||
}
|
||||
} {10 15 101 sort}
|
||||
} {10 15 101 nosort}
|
||||
do_test collate4-6.3 {
|
||||
cksort {
|
||||
SELECT * FROM collate4t1 ORDER BY oid||'' COLLATE TEXT;
|
||||
|
136
test/cursor.test
Normal file
136
test/cursor.test
Normal file
@ -0,0 +1,136 @@
|
||||
# 2004 November 22
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
#*************************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is DECLARE...CURSOR functionality
|
||||
#
|
||||
# $Id: cursor.test,v 1.1 2004/11/22 19:12:21 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_OMIT_CURSOR is defined, omit this file.
|
||||
ifcapable {!cursor} {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
########
|
||||
# Test the logic that creates and destroys cursors
|
||||
########
|
||||
do_test cursor-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a,b,c);
|
||||
CREATE INDEX t1i1 ON t1(a);
|
||||
CREATE INDEX t1i2 ON t1(b,c);
|
||||
}
|
||||
execsql {
|
||||
DECLARE c1 CURSOR FOR SELECT c FROM t1 ORDER BY a;
|
||||
}
|
||||
} {}
|
||||
ifcapable schema_pragmas {
|
||||
do_test cursor-1.2 {
|
||||
execsql {PRAGMA cursor_list}
|
||||
} {0 c1}
|
||||
}
|
||||
do_test cursor-1.3 {
|
||||
execsql {
|
||||
DECLARE c2 CURSOR FOR SELECT a FROM t1 ORDER BY b, c;
|
||||
}
|
||||
} {}
|
||||
ifcapable schema_pragmas {
|
||||
do_test cursor-1.4 {
|
||||
execsql {PRAGMA cursor_list}
|
||||
} {0 c1 1 c2}
|
||||
}
|
||||
do_test cursor-1.5 {
|
||||
catchsql {
|
||||
CLOSE c3;
|
||||
}
|
||||
} {1 {no such cursor: c3}}
|
||||
ifcapable schema_pragmas {
|
||||
do_test cursor-1.6 {
|
||||
execsql {PRAGMA cursor_list}
|
||||
} {0 c1 1 c2}
|
||||
}
|
||||
do_test cursor-1.7 {
|
||||
catchsql {
|
||||
CLOSE c1;
|
||||
}
|
||||
} {0 {}}
|
||||
ifcapable schema_pragmas {
|
||||
do_test cursor-1.8 {
|
||||
execsql {PRAGMA cursor_list}
|
||||
} {1 c2}
|
||||
}
|
||||
do_test cursor-1.9 {
|
||||
catchsql {
|
||||
CLOSE c1;
|
||||
}
|
||||
} {1 {no such cursor: c1}}
|
||||
ifcapable schema_pragmas {
|
||||
do_test cursor-1.10 {
|
||||
execsql {PRAGMA cursor_list}
|
||||
} {1 c2}
|
||||
}
|
||||
do_test cursor-1.11 {
|
||||
catchsql {
|
||||
DECLARE c2 CURSOR FOR SELECT * FROM t1;
|
||||
}
|
||||
} {1 {another cursor named c2 already exists}}
|
||||
do_test cursor-1.12 {
|
||||
catchsql {
|
||||
DECLARE c3 CURSOR FOR SELECT * FROM t1;
|
||||
}
|
||||
} {0 {}}
|
||||
ifcapable schema_pragmas {
|
||||
do_test cursor-1.13 {
|
||||
execsql {PRAGMA cursor_list}
|
||||
} {0 c3 1 c2}
|
||||
}
|
||||
do_test cursor-1.14 {
|
||||
execsql {
|
||||
CLOSE c2;
|
||||
CLOSE c3;
|
||||
}
|
||||
} {}
|
||||
ifcapable schema_pragmas {
|
||||
do_test cursor-1.15 {
|
||||
execsql {PRAGMA cursor_list}
|
||||
} {}
|
||||
}
|
||||
|
||||
set all {}
|
||||
for {set i 1} {$i<=50} {incr i} {
|
||||
lappend all [expr {$i-1}] x$i
|
||||
do_test cursor-2.1.$i.1 {
|
||||
execsql "DECLARE x$i CURSOR FOR SELECT * FROM t1"
|
||||
} {}
|
||||
ifcapable schema_pragmas {
|
||||
do_test cursor-2.1.$i.2 {
|
||||
execsql {PRAGMA cursor_list}
|
||||
} $all
|
||||
}
|
||||
}
|
||||
for {set i 1} {$i<=50} {incr i} {
|
||||
set all [lrange $all 2 end]
|
||||
do_test cursor-2.2.$i.1 {
|
||||
execsql "CLOSE x$i"
|
||||
} {}
|
||||
ifcapable schema_pragmas {
|
||||
do_test cursor-2.2.$i.2 {
|
||||
execsql {PRAGMA cursor_list}
|
||||
} $all
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
finish_test
|
@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the use of indices in WHERE clases.
|
||||
#
|
||||
# $Id: where.test,v 1.23 2004/11/03 16:27:02 drh Exp $
|
||||
# $Id: where.test,v 1.24 2004/11/22 19:12:21 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@ -508,6 +508,47 @@ do_test where-6.19 {
|
||||
SELECT y FROM t1 ORDER BY w LIMIT 3;
|
||||
}
|
||||
} {4 9 16 nosort}
|
||||
do_test where-6.20 {
|
||||
cksort {
|
||||
SELECT y FROM t1 ORDER BY rowid LIMIT 3;
|
||||
}
|
||||
} {4 9 16 nosort}
|
||||
do_test where-6.21 {
|
||||
cksort {
|
||||
SELECT y FROM t1 ORDER BY rowid, y LIMIT 3;
|
||||
}
|
||||
} {4 9 16 nosort}
|
||||
do_test where-6.22 {
|
||||
cksort {
|
||||
SELECT y FROM t1 ORDER BY rowid, y DESC LIMIT 3;
|
||||
}
|
||||
} {4 9 16 nosort}
|
||||
do_test where-6.23 {
|
||||
cksort {
|
||||
SELECT y FROM t1 WHERE y>4 ORDER BY rowid, w, x LIMIT 3;
|
||||
}
|
||||
} {9 16 25 nosort}
|
||||
do_test where-6.24 {
|
||||
cksort {
|
||||
SELECT y FROM t1 WHERE y>=9 ORDER BY rowid, x DESC, w LIMIT 3;
|
||||
}
|
||||
} {9 16 25 nosort}
|
||||
do_test where-6.25 {
|
||||
cksort {
|
||||
SELECT y FROM t1 WHERE y>4 AND y<25 ORDER BY rowid;
|
||||
}
|
||||
} {9 16 nosort}
|
||||
do_test where-6.26 {
|
||||
cksort {
|
||||
SELECT y FROM t1 WHERE y>=4 AND y<=25 ORDER BY oid;
|
||||
}
|
||||
} {4 9 16 25 nosort}
|
||||
do_test where-6.27 {
|
||||
cksort {
|
||||
SELECT y FROM t1 WHERE y<=25 ORDER BY _rowid_, w+y;
|
||||
}
|
||||
} {4 9 16 25 nosort}
|
||||
|
||||
|
||||
# Tests for reverse-order sorting.
|
||||
#
|
||||
@ -661,6 +702,31 @@ do_test where-7.30 {
|
||||
SELECT w FROM t1 WHERE x=6 AND y>=10201 ORDER BY y DESC;
|
||||
}
|
||||
} {100 nosort}
|
||||
do_test where-7.31 {
|
||||
cksort {
|
||||
SELECT y FROM t1 ORDER BY rowid DESC LIMIT 3
|
||||
}
|
||||
} {10201 10000 9801 nosort}
|
||||
do_test where-7.32 {
|
||||
cksort {
|
||||
SELECT y FROM t1 WHERE y<25 ORDER BY rowid DESC, x
|
||||
}
|
||||
} {16 9 4 nosort}
|
||||
do_test where-7.33 {
|
||||
cksort {
|
||||
SELECT y FROM t1 WHERE y<=25 ORDER BY rowid DESC, x
|
||||
}
|
||||
} {25 16 9 4 nosort}
|
||||
do_test where-7.34 {
|
||||
cksort {
|
||||
SELECT y FROM t1 WHERE y<25 AND y>4 ORDER BY rowid DESC, y DESC
|
||||
}
|
||||
} {16 9 nosort}
|
||||
do_test where-7.35 {
|
||||
cksort {
|
||||
SELECT y FROM t1 WHERE y<25 AND y>=4 ORDER BY rowid DESC
|
||||
}
|
||||
} {16 9 4 nosort}
|
||||
|
||||
do_test where-8.1 {
|
||||
execsql {
|
||||
|
Reference in New Issue
Block a user