1*b79c718fSdrh# 2014-04-25 2*b79c718fSdrh# 3*b79c718fSdrh# The author disclaims copyright to this source code. In place of 4*b79c718fSdrh# a legal notice, here is a blessing: 5*b79c718fSdrh# 6*b79c718fSdrh# May you do good and not evil. 7*b79c718fSdrh# May you find forgiveness for yourself and forgive others. 8*b79c718fSdrh# May you share freely, never taking more than you give. 9*b79c718fSdrh# 10*b79c718fSdrh#*********************************************************************** 11*b79c718fSdrh# This file implements regression tests for SQLite library. The 12*b79c718fSdrh# focus of this file is testing ORDER BY optimizations on joins 13*b79c718fSdrh# that involve virtual tables. 14*b79c718fSdrh# 15*b79c718fSdrh 16*b79c718fSdrh 17*b79c718fSdrhset testdir [file dirname $argv0] 18*b79c718fSdrhsource $testdir/tester.tcl 19*b79c718fSdrhset ::testprefix orderby7 20*b79c718fSdrh 21*b79c718fSdrhifcapable !fts3 { 22*b79c718fSdrh finish_test 23*b79c718fSdrh return 24*b79c718fSdrh} 25*b79c718fSdrh 26*b79c718fSdrhdo_execsql_test 1.0 { 27*b79c718fSdrh CREATE VIRTUAL TABLE fts USING fts3(content TEXT); 28*b79c718fSdrh INSERT INTO fts(rowid,content) 29*b79c718fSdrh VALUES(1,'this is a test of the fts3 virtual'), 30*b79c718fSdrh (2,'table used as part of a join together'), 31*b79c718fSdrh (3,'with the DISTINCT keyword. There was'), 32*b79c718fSdrh (4,'a bug at one time (2013-06 through 2014-04)'), 33*b79c718fSdrh (5,'that prevented this from working correctly.'), 34*b79c718fSdrh (11,'a row that occurs twice'), 35*b79c718fSdrh (12,'a row that occurs twice'); 36*b79c718fSdrh 37*b79c718fSdrh CREATE TABLE t1(x TEXT PRIMARY KEY, y); 38*b79c718fSdrh INSERT OR IGNORE INTO t1 SELECT content, rowid+100 FROM fts; 39*b79c718fSdrh} {} 40*b79c718fSdrhdo_execsql_test 1.1 { 41*b79c718fSdrh SELECT DISTINCT fts.rowid, t1.y 42*b79c718fSdrh FROM fts, t1 43*b79c718fSdrh WHERE fts MATCH 'that twice' 44*b79c718fSdrh AND content=x 45*b79c718fSdrh ORDER BY y; 46*b79c718fSdrh} {11 111 12 111} 47*b79c718fSdrhdo_execsql_test 1.2 { 48*b79c718fSdrh SELECT DISTINCT fts.rowid, t1.x 49*b79c718fSdrh FROM fts, t1 50*b79c718fSdrh WHERE fts MATCH 'that twice' 51*b79c718fSdrh AND content=x 52*b79c718fSdrh ORDER BY 1; 53*b79c718fSdrh} {11 {a row that occurs twice} 12 {a row that occurs twice}} 54*b79c718fSdrhdo_execsql_test 1.3 { 55*b79c718fSdrh SELECT DISTINCT t1.x 56*b79c718fSdrh FROM fts, t1 57*b79c718fSdrh WHERE fts MATCH 'that twice' 58*b79c718fSdrh AND content=x 59*b79c718fSdrh ORDER BY 1; 60*b79c718fSdrh} {{a row that occurs twice}} 61*b79c718fSdrhdo_execsql_test 1.4 { 62*b79c718fSdrh SELECT t1.x 63*b79c718fSdrh FROM fts, t1 64*b79c718fSdrh WHERE fts MATCH 'that twice' 65*b79c718fSdrh AND content=x 66*b79c718fSdrh ORDER BY 1; 67*b79c718fSdrh} {{a row that occurs twice} {a row that occurs twice}} 68*b79c718fSdrhdo_execsql_test 1.5 { 69*b79c718fSdrh SELECT DISTINCT t1.x 70*b79c718fSdrh FROM fts, t1 71*b79c718fSdrh WHERE fts MATCH 'that twice' 72*b79c718fSdrh AND content=x; 73*b79c718fSdrh} {{a row that occurs twice}} 74*b79c718fSdrhdo_execsql_test 1.6 { 75*b79c718fSdrh SELECT t1.x 76*b79c718fSdrh FROM fts, t1 77*b79c718fSdrh WHERE fts MATCH 'that twice' 78*b79c718fSdrh AND content=x; 79*b79c718fSdrh} {{a row that occurs twice} {a row that occurs twice}} 80*b79c718fSdrh 81*b79c718fSdrhdo_execsql_test 2.1 { 82*b79c718fSdrh SELECT DISTINCT t1.x 83*b79c718fSdrh FROM fts, t1 84*b79c718fSdrh WHERE fts.rowid=11 85*b79c718fSdrh AND content=x 86*b79c718fSdrh ORDER BY fts.rowid; 87*b79c718fSdrh} {{a row that occurs twice}} 88*b79c718fSdrhdo_execsql_test 2.2 { 89*b79c718fSdrh SELECT DISTINCT t1.* 90*b79c718fSdrh FROM fts, t1 91*b79c718fSdrh WHERE fts.rowid=11 92*b79c718fSdrh AND content=x 93*b79c718fSdrh ORDER BY fts.rowid; 94*b79c718fSdrh} {{a row that occurs twice} 111} 95*b79c718fSdrhdo_execsql_test 2.3 { 96*b79c718fSdrh SELECT DISTINCT t1.* 97*b79c718fSdrh FROM fts, t1 98*b79c718fSdrh WHERE fts.rowid=11 99*b79c718fSdrh AND content=x 100*b79c718fSdrh ORDER BY t1.y 101*b79c718fSdrh} {{a row that occurs twice} 111} 102*b79c718fSdrh 103*b79c718fSdrh 104*b79c718fSdrh 105*b79c718fSdrh 106*b79c718fSdrhfinish_test 107