SQLite4
Check-in [187316a0dc]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix a problem to do with copying from the sorter to a temporary table in select.c.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 187316a0dc1b8d4a485f91c1018c74805f5c1fbd
User & Date: dan 2012-04-23 18:38:38
Context
2012-04-23
19:49
Towards an sqlite4_env object that defines the run-time environment. This is not a complete check-in, just an incremental change (hopefully) in the right direction. check-in: 88ac7f6772 user: drh tags: trunk
18:38
Fix a problem to do with copying from the sorter to a temporary table in select.c. check-in: 187316a0dc user: dan tags: trunk
16:50
Change the tcl interface so that tcl scripts may specify collation sequence xMkKey callbacks. check-in: 6ebe82280d user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/kvmem.c.

412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
  }else if( pOld->pBefore==0 ){
    *ppParent = pBalance = pOld->pAfter;
    pBalance->pUp = pOld->pUp;
  }else if( pOld->pAfter==0 ){
    *ppParent = pBalance = pOld->pBefore;
    pBalance->pUp = pOld->pUp;
  }
  assertUpPointers(p->pRoot);
  p->pRoot = kvmemBalance(pBalance);
  assertUpPointers(p->pRoot);
  kvmemNodeUnref(pOld);
}

/*
** End of low-level access routines
***************************************************************************
** Interface routines follow







<

<







412
413
414
415
416
417
418

419

420
421
422
423
424
425
426
  }else if( pOld->pBefore==0 ){
    *ppParent = pBalance = pOld->pAfter;
    pBalance->pUp = pOld->pUp;
  }else if( pOld->pAfter==0 ){
    *ppParent = pBalance = pOld->pBefore;
    pBalance->pUp = pOld->pUp;
  }

  p->pRoot = kvmemBalance(pBalance);

  kvmemNodeUnref(pOld);
}

/*
** End of low-level access routines
***************************************************************************
** Interface routines follow

Changes to src/select.c.

952
953
954
955
956
957
958

959
960
961
962
963
964
965
  }
  switch( eDest ){
    case SRT_Table:
    case SRT_EphemTab: {
      testcase( eDest==SRT_Table );
      testcase( eDest==SRT_EphemTab );
      sqlite4VdbeAddOp2(v, OP_NewRowid, iParm, regRowid);

      sqlite4VdbeAddOp3(v, OP_Insert, iParm, regRow, regRowid);
      sqlite4VdbeChangeP5(v, OPFLAG_APPEND);
      break;
    }
#ifndef SQLITE_OMIT_SUBQUERY
    case SRT_Set: {
      assert( nColumn==1 );







>







952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
  }
  switch( eDest ){
    case SRT_Table:
    case SRT_EphemTab: {
      testcase( eDest==SRT_Table );
      testcase( eDest==SRT_EphemTab );
      sqlite4VdbeAddOp2(v, OP_NewRowid, iParm, regRowid);
      sqlite4VdbeAddOp2(v, OP_RowData, iTab, regRow);
      sqlite4VdbeAddOp3(v, OP_Insert, iParm, regRow, regRowid);
      sqlite4VdbeChangeP5(v, OPFLAG_APPEND);
      break;
    }
#ifndef SQLITE_OMIT_SUBQUERY
    case SRT_Set: {
      assert( nColumn==1 );

Changes to test/permutations.test.

129
130
131
132
133
134
135
136

137
138
139
140
141
142
143
144
145
146
#   quick
#   full
#
lappend ::testsuitelist xxx

test_suite "src4" -prefix "" -description {
} -files {
  simple.test fkey1.test conflict.test trigger2.test select1.test

  where.test select3.test select5.test select7.test select8.test
  select9.test selectA.test selectB.test selectC.test

  collate1.test
}

test_suite "veryquick" -prefix "" -description {
  "Very" quick test suite. Runs in less than 5 minutes on a workstation. 
  This test suite is the same as the "quick" tests, except that some files
  that test malloc and IO errors are omitted.







|
>
|
|
<







129
130
131
132
133
134
135
136
137
138
139

140
141
142
143
144
145
146
#   quick
#   full
#
lappend ::testsuitelist xxx

test_suite "src4" -prefix "" -description {
} -files {
  simple.test fkey1.test conflict.test trigger2.test where.test 
  select1.test select2.test select3.test select4.test select5.test 
  select6.test select7.test select8.test select9.test selectA.test 
  selectB.test selectC.test 

  collate1.test
}

test_suite "veryquick" -prefix "" -description {
  "Very" quick test suite. Runs in less than 5 minutes on a workstation. 
  This test suite is the same as the "quick" tests, except that some files
  that test malloc and IO errors are omitted.

Changes to test/select2.test.

113
114
115
116
117
118
119
120
121
122
123

124
125
126
127
128

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
do_test select2-3.2b {
  execsql {SELECT f1 FROM tbl2 WHERE 1000=f2}
} {500}
do_test select2-3.2c {
  execsql {SELECT f1 FROM tbl2 WHERE f2=1000}
} {500}
do_test select2-3.2d {
  set sqlite_search_count 0
  execsql {SELECT * FROM tbl2 WHERE 1000=f2}
  set sqlite_search_count
} {3}

do_test select2-3.2e {
  set sqlite_search_count 0
  execsql {SELECT * FROM tbl2 WHERE f2=1000}
  set sqlite_search_count
} {3}


# Make sure queries run faster with an index than without
#
do_test select2-3.3 {
  execsql {DROP INDEX idx1}
  set sqlite_search_count 0
  execsql {SELECT f1 FROM tbl2 WHERE f2==2000}
  set sqlite_search_count
} {29999}

# Make sure we can optimize functions in the WHERE clause that
# use fields from two or more different table.  (Bug #6)
#
do_test select2-4.1 {
  execsql {
    CREATE TABLE aa(a);







<

<
<
>

<

<
<
>





<

<
|







113
114
115
116
117
118
119

120


121
122

123


124
125
126
127
128
129

130

131
132
133
134
135
136
137
138
do_test select2-3.2b {
  execsql {SELECT f1 FROM tbl2 WHERE 1000=f2}
} {500}
do_test select2-3.2c {
  execsql {SELECT f1 FROM tbl2 WHERE f2=1000}
} {500}
do_test select2-3.2d {

  execsql {SELECT * FROM tbl2 WHERE 1000=f2}


} {500 1000 1500}
do_test select2-3.2e {

  execsql {SELECT * FROM tbl2 WHERE f2=1000}


} {500 1000 1500}

# Make sure queries run faster with an index than without
#
do_test select2-3.3 {
  execsql {DROP INDEX idx1}

  execsql {SELECT f1 FROM tbl2 WHERE f2==2000}

} {1000}

# Make sure we can optimize functions in the WHERE clause that
# use fields from two or more different table.  (Bug #6)
#
do_test select2-4.1 {
  execsql {
    CREATE TABLE aa(a);

Changes to test/simple.test.

970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986























987
988
989
  binary scan $zIn c* lChar
  foreach c $lChar {
    append res [format "%02X" [expr 255-$c]]
  }
  set res
}
db collate reverse reverse_cmp reverse_mkkey

do_execsql_test 48.3 {
    SELECT * FROM t1 WHERE a<5 UNION SELECT * FROM t2 WHERE d>=5 
    ORDER BY 2 COLLATE reverse, 1
} { 
  3 {} {}            6 {} {}         9 {} {} 
  2 two II           10 twenty XL    5 ten XX 
  8 sixteen XXXII    1 one I         7 fourteen XXVIII 
  4 four IV
}
























finish_test








<









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



970
971
972
973
974
975
976

977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
  binary scan $zIn c* lChar
  foreach c $lChar {
    append res [format "%02X" [expr 255-$c]]
  }
  set res
}
db collate reverse reverse_cmp reverse_mkkey

do_execsql_test 48.3 {
    SELECT * FROM t1 WHERE a<5 UNION SELECT * FROM t2 WHERE d>=5 
    ORDER BY 2 COLLATE reverse, 1
} { 
  3 {} {}            6 {} {}         9 {} {} 
  2 two II           10 twenty XL    5 ten XX 
  8 sixteen XXXII    1 one I         7 fourteen XXVIII 
  4 four IV
}

#-------------------------------------------------------------------------
reset_db
do_execsql_test 49.1 {
  CREATE TABLE t1(a, b);

  INSERT INTO t1 VALUES(1, 5);
  INSERT INTO t1 VALUES(2, 4);
  INSERT INTO t1 VALUES(3, 3);
  INSERT INTO t1 VALUES(4, 2);
  INSERT INTO t1 VALUES(5, 1);
}

do_execsql_test 49.2 {
    SELECT a, b FROM t1 ORDER BY a LIMIT 2 OFFSET 2
} {3 3   4 2}

do_execsql_test 49.3 {
  SELECT * FROM (
    SELECT a, b FROM t1 ORDER BY a LIMIT 2 OFFSET 2
  ) ORDER BY 2;
} {4 2   3 3}


finish_test