From da55c48a9a96cf2aff9fb3dc80c0dc80a8662c80 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 5 Dec 2008 00:00:07 +0000 Subject: [PATCH] Expand table.* properly on a USING or a NATURAL join. Ticket #3522. (CVS 5979) FossilOrigin-Name: 06d206ef7d5e433ccde347d63dfcd2177545e1fd --- manifest | 15 ++++++----- manifest.uuid | 2 +- src/select.c | 4 +-- test/join.test | 67 ++++++++++++++++++++++++++++++++++++++++++++++- test/tkt3522.test | 43 ++++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+), 11 deletions(-) create mode 100644 test/tkt3522.test diff --git a/manifest b/manifest index ad640ea59f..3fcb6f5430 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\ssegfault\sthat\scan\soccur\sin\sthe\sRowSet\sobject\sfollowing\sa\smalloc\nfailure.\s(CVS\s5978) -D 2008-12-04T22:17:56 +C Expand\stable.*\sproperly\son\sa\sUSING\sor\sa\sNATURAL\sjoin.\s\sTicket\s#3522.\s(CVS\s5979) +D 2008-12-05T00:00:07 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in f7e4c81c347b04f7b0f1c1b081a168645d7b8af7 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -151,7 +151,7 @@ F src/printf.c e29d9475c63e1dbfae005b98da3a60e07b5c1ca5 F src/random.c a87afbd598aa877e23ac676ee92fd8ee5c786a51 F src/resolve.c 4af5391d2b4c1d6c583a6805ac6660181de4545b F src/rowset.c 2256fa4a928f750e2f3d6fc733523034beceb1d6 -F src/select.c b296a7b53dd0b2c42ab8b67d969e2c924529008c +F src/select.c e2127ce827914824c284046c66bf9259745b6be8 F src/shell.c 838c745e7ac5c9fe17bc996224ed2f928d178bb2 F src/sqlite.h.in b5d50f12fb9c7460a4ddfef8c1e799afaabefebf F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17 @@ -392,7 +392,7 @@ F test/ioerr2.test a8428580ce12ce67a6f16d85e2640fa6ce2da888 F test/ioerr3.test d3cec5e1a11ad6d27527d0d38573fbff14c71bdd F test/ioerr4.test fc6eddfec2efc2f1ed217b9eae4c1c1d3516ce86 F test/ioerr5.test 89f69b09a6b5d4f5bbfe58d4231f28236d842dcb -F test/join.test e0664af757049ba1f19a0d42c470a58299f36a3e +F test/join.test c5696c7e7efd8b3780c9308e4511742a937fe660 F test/join2.test f2171c265e57ee298a27e57e7051d22962f9f324 F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0 F test/join4.test 1a352e4e267114444c29266ce79e941af5885916 @@ -582,6 +582,7 @@ F test/tkt3461.test 5a63e8d8ee5ce00f076b1e2f82aba5480a0f14ed F test/tkt3472.test 98c7e54b8fef2b1266a552a66c8e5d88a6908d1d F test/tkt3493.test 8472b3464e49a27ff7271308eec46154209e667b F test/tkt3508.test d9e285ff91731247d4673f9252fe5934639d7f0d +F test/tkt3522.test 22ce2ebbcb04a6be56c0977d405c207967318fd6 F test/tkt35xx.test 53bca895091e968126a858ee7da186f59f328994 F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7 F test/trace.test 951cd0f5f571e7f36bf7bfe04be70f90fb16fb00 @@ -662,7 +663,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 39a0750b49cf55e9c0927169ca47db909f5c16ea -R 4a7599da73fd5a79c2dfb0d9f2d60746 +P cb0f1658d3db7ccf80843d66fa85af8de44710d0 +R 772817d081b9a8725e3ec2153391efbc U drh -Z 69484d9ad61e9734a4c2ad4dd121e991 +Z 0bfef847b98139757e4dba73ff4e74e2 diff --git a/manifest.uuid b/manifest.uuid index b47ea0be37..e49fab9c6c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cb0f1658d3db7ccf80843d66fa85af8de44710d0 \ No newline at end of file +06d206ef7d5e433ccde347d63dfcd2177545e1fd \ No newline at end of file diff --git a/src/select.c b/src/select.c index 0c6f1449e1..48ded47a6e 100644 --- a/src/select.c +++ b/src/select.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.488 2008/11/21 16:22:18 danielk1977 Exp $ +** $Id: select.c,v 1.489 2008/12/05 00:00:07 drh Exp $ */ #include "sqliteInt.h" @@ -3152,7 +3152,7 @@ static int selectExpander(Walker *pWalker, Select *p){ continue; } - if( i>0 ){ + if( i>0 && zTName==0 ){ struct SrcList_item *pLeft = &pTabList->a[i-1]; if( (pLeft[1].jointype & JT_NATURAL)!=0 && columnIndex(pLeft->pTab, zName)>=0 ){ diff --git a/test/join.test b/test/join.test index 3512ce6c48..59901b0e73 100644 --- a/test/join.test +++ b/test/join.test @@ -12,7 +12,7 @@ # # This file implements tests for joins, including outer joins. # -# $Id: join.test,v 1.25 2008/08/14 00:19:49 drh Exp $ +# $Id: join.test,v 1.26 2008/12/05 00:00:07 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -61,6 +61,40 @@ do_test join-1.3.4 { SELECT b FROM t1 NATURAL JOIN t2; } } {2 3} + +# ticket #3522 +do_test join-1.3.5 { + execsql2 { + SELECT t2.* FROM t2 NATURAL JOIN t1 + } +} {b 2 c 3 d 4 b 3 c 4 d 5} +do_test join-1.3.6 { + execsql2 { + SELECT xyzzy.* FROM t2 AS xyzzy NATURAL JOIN t1 + } +} {b 2 c 3 d 4 b 3 c 4 d 5} +do_test join-1.3.7 { + execsql2 { + SELECT t1.* FROM t2 NATURAL JOIN t1 + } +} {a 1 b 2 c 3 a 2 b 3 c 4} +do_test join-1.3.8 { + execsql2 { + SELECT xyzzy.* FROM t2 NATURAL JOIN t1 AS xyzzy + } +} {a 1 b 2 c 3 a 2 b 3 c 4} +do_test join-1.3.9 { + execsql2 { + SELECT aaa.*, bbb.* FROM t2 AS aaa NATURAL JOIN t1 AS bbb + } +} {b 2 c 3 d 4 a 1 b 2 c 3 b 3 c 4 d 5 a 2 b 3 c 4} +do_test join-1.3.10 { + execsql2 { + SELECT t1.*, t2.* FROM t2 NATURAL JOIN t1 + } +} {a 1 b 2 c 3 b 2 c 3 d 4 a 2 b 3 c 4 b 3 c 4 d 5} + + do_test join-1.4.1 { execsql2 { SELECT * FROM t1 INNER JOIN t2 USING(b,c); @@ -86,6 +120,19 @@ do_test join-1.4.5 { SELECT b FROM t1 JOIN t2 USING(b); } } {2 3} + +# Ticket #3522 +do_test join-1.4.6 { + execsql2 { + SELECT t1.* FROM t1 JOIN t2 USING(b); + } +} {a 1 b 2 c 3 a 2 b 3 c 4} +do_test join-1.4.7 { + execsql2 { + SELECT t2.* FROM t1 JOIN t2 USING(b); + } +} {b 2 c 3 d 4 b 3 c 4 d 5} + do_test join-1.5 { execsql2 { SELECT * FROM t1 INNER JOIN t2 USING(b); @@ -192,6 +239,24 @@ do_test join-2.1 { SELECT * FROM t1 NATURAL LEFT JOIN t2; } } {1 2 3 4 2 3 4 5 3 4 5 {}} + +# ticket #3522 +do_test join-2.1.1 { + execsql2 { + SELECT * FROM t1 NATURAL LEFT JOIN t2; + } +} {a 1 b 2 c 3 d 4 a 2 b 3 c 4 d 5 a 3 b 4 c 5 d {}} +do_test join-2.1.2 { + execsql2 { + SELECT t1.* FROM t1 NATURAL LEFT JOIN t2; + } +} {a 1 b 2 c 3 a 2 b 3 c 4 a 3 b 4 c 5} +do_test join-2.1.3 { + execsql2 { + SELECT t2.* FROM t1 NATURAL LEFT JOIN t2; + } +} {b 2 c 3 d 4 b 3 c 4 d 5 b {} c {} d {}} + do_test join-2.2 { execsql { SELECT * FROM t2 NATURAL LEFT OUTER JOIN t1; diff --git a/test/tkt3522.test b/test/tkt3522.test new file mode 100644 index 0000000000..998d489345 --- /dev/null +++ b/test/tkt3522.test @@ -0,0 +1,43 @@ +# 2008 December 4 +# +# 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. +# +# This file is a verification that the bugs identified in ticket +# #3522 have been fixed. +# +# $Id: tkt3522.test,v 1.1 2008/12/05 00:00:07 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_test tkt3522-1.1 { + db eval { + CREATE TABLE tab4( + col0 INTEGER, + col1 INTEGER, + col2 INTEGER, + col3 INTEGER, + col4 INTEGER + ); + SELECT cor1.* + FROM tab4 AS cor0 + JOIN tab4 AS cor1 USING ( col4, col3, col2, col1, col0 ); + } +} {} +do_test tkt3522-1.2 { + db eval { + CREATE TABLE tab1(col0 INTEGER); + CREATE TABLE tab2(col0 INTEGER); + SELECT cor0.* FROM tab1 NATURAL JOIN tab2 AS cor0; + } +} {} + +finish_test