os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/tkt2640.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/tkt2640.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,124 @@
     1.4 +# 2007 Sep 12
     1.5 +#
     1.6 +# The author disclaims copyright to this source code. In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#***********************************************************************
    1.14 +#
    1.15 +# This file is to test that ticket #2640 has been fixed.
    1.16 +#
    1.17 +# $Id: tkt2640.test,v 1.3 2008/08/04 03:51:24 danielk1977 Exp $
    1.18 +#
    1.19 +
    1.20 +# The problem in ticket #2640 was that the query optimizer was 
    1.21 +# not recognizing all uses of tables within subqueries in the
    1.22 +# WHERE clause.  If the subquery contained a compound SELECT,
    1.23 +# then tables that were used by terms of the compound other than
    1.24 +# the last term would not be recognized as dependencies.
    1.25 +# So if one of the SELECT statements within a compound made
    1.26 +# use of a table that occurs later in a join, the query
    1.27 +# optimizer would not recognize this and would try to evaluate
    1.28 +# the subquery too early, before that tables value had been
    1.29 +# established.
    1.30 +
    1.31 +set testdir [file dirname $argv0]
    1.32 +source $testdir/tester.tcl
    1.33 +
    1.34 +ifcapable !subquery||!compound {
    1.35 +  finish_test
    1.36 +  return
    1.37 +}
    1.38 +
    1.39 +do_test tkt2640-1.1 {
    1.40 +  execsql {
    1.41 +    CREATE TABLE persons(person_id, name);
    1.42 +    INSERT INTO persons VALUES(1,'fred');
    1.43 +    INSERT INTO persons VALUES(2,'barney');
    1.44 +    INSERT INTO persons VALUES(3,'wilma');
    1.45 +    INSERT INTO persons VALUES(4,'pebbles');
    1.46 +    INSERT INTO persons VALUES(5,'bambam');
    1.47 +    CREATE TABLE directors(person_id);
    1.48 +    INSERT INTO directors VALUES(5);
    1.49 +    INSERT INTO directors VALUES(3);
    1.50 +    CREATE TABLE writers(person_id);
    1.51 +    INSERT INTO writers VALUES(2);
    1.52 +    INSERT INTO writers VALUES(3);
    1.53 +    INSERT INTO writers VALUES(4);
    1.54 +    SELECT DISTINCT p.name
    1.55 +      FROM persons p, directors d
    1.56 +     WHERE d.person_id=p.person_id
    1.57 +       AND NOT EXISTS (
    1.58 +             SELECT person_id FROM directors d1 WHERE d1.person_id=p.person_id
    1.59 +             EXCEPT
    1.60 +             SELECT person_id FROM writers w
    1.61 +           );
    1.62 +  }
    1.63 +} {wilma}
    1.64 +do_test tkt2640-1.2 {
    1.65 +  execsql {
    1.66 +    SELECT DISTINCT p.name
    1.67 +      FROM persons p CROSS JOIN directors d
    1.68 +     WHERE d.person_id=p.person_id
    1.69 +       AND NOT EXISTS (
    1.70 +             SELECT person_id FROM directors d1 WHERE d1.person_id=p.person_id
    1.71 +             EXCEPT
    1.72 +             SELECT person_id FROM writers w
    1.73 +           );
    1.74 +  }
    1.75 +} {wilma}
    1.76 +do_test tkt2640-1.3 {
    1.77 +  execsql {
    1.78 +    SELECT DISTINCT p.name
    1.79 +      FROM directors d CROSS JOIN persons p
    1.80 +     WHERE d.person_id=p.person_id
    1.81 +       AND NOT EXISTS (
    1.82 +             SELECT person_id FROM directors d1 WHERE d1.person_id=p.person_id
    1.83 +             EXCEPT
    1.84 +             SELECT person_id FROM writers w
    1.85 +           );
    1.86 +  }
    1.87 +} {wilma}
    1.88 +do_test tkt2640-1.4 {
    1.89 +  execsql {
    1.90 +    SELECT DISTINCT p.name
    1.91 +      FROM persons p, directors d
    1.92 +     WHERE d.person_id=p.person_id
    1.93 +       AND NOT EXISTS (
    1.94 +             SELECT person_id FROM directors d1 WHERE d1.person_id=d.person_id
    1.95 +             EXCEPT
    1.96 +             SELECT person_id FROM writers w
    1.97 +           );
    1.98 +  }
    1.99 +} {wilma}
   1.100 +do_test tkt2640-1.5 {
   1.101 +  execsql {
   1.102 +    SELECT DISTINCT p.name
   1.103 +      FROM persons p CROSS JOIN directors d
   1.104 +     WHERE d.person_id=p.person_id
   1.105 +       AND NOT EXISTS (
   1.106 +             SELECT person_id FROM directors d1 WHERE d1.person_id=d.person_id
   1.107 +             EXCEPT
   1.108 +             SELECT person_id FROM writers w
   1.109 +           );
   1.110 +  }
   1.111 +} {wilma}
   1.112 +do_test tkt2640-1.6 {
   1.113 +  execsql {
   1.114 +    SELECT DISTINCT p.name
   1.115 +      FROM directors d CROSS JOIN persons p
   1.116 +     WHERE d.person_id=p.person_id
   1.117 +       AND NOT EXISTS (
   1.118 +             SELECT person_id FROM directors d1 WHERE d1.person_id=d.person_id
   1.119 +             EXCEPT
   1.120 +             SELECT person_id FROM writers w
   1.121 +           );
   1.122 +  }
   1.123 +} {wilma}
   1.124 +
   1.125 +
   1.126 +
   1.127 +finish_test