]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Retain the affinity of an expression in a WHERE clause when it is transformed to...
authordan <dan@noemail.net>
Tue, 20 Aug 2019 11:43:44 +0000 (11:43 +0000)
committerdan <dan@noemail.net>
Tue, 20 Aug 2019 11:43:44 +0000 (11:43 +0000)
FossilOrigin-Name: 511da0815673ca4a176aa61dc23a8231b2ab77e8363fc184a78b6e17dba64d49

manifest
manifest.uuid
src/wherecode.c
test/affinity2.test

index 1b402b92766c76705b382dfa9cb89f1708e253c6..87f84210976c3909fdfe5ac08bd676c8831bc2d4 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\stypo\sand\sa\sharmless\scompiler\swarning.
-D 2019-08-20T02:19:26.962
+C Retain\sthe\saffinity\sof\san\sexpression\sin\sa\sWHERE\sclause\swhen\sit\sis\stransformed\sto\sa\sreference\sto\san\sindex\scolumn\son\sthe\ssame\sexpression.\sFix\sfor\s[f043b113].
+D 2019-08-20T11:43:44.838
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -611,11 +611,11 @@ F src/wal.h 606292549f5a7be50b6227bd685fa76e3a4affad71bb8ac5ce4cb5c79f6a176a
 F src/walker.c d5a94907dcac990e31976be9dc769d17f6a806782593d6aec9d760ee01ec22cd
 F src/where.c 2fac51d2420f05ab6f644f1813d4f73f6214304836fd9b22345738d943faad9b
 F src/whereInt.h 2082fc2bd1eb66cb236a1a3c4b250e33d2bad9e43a0486a2cf9e4e211c58f3eb
-F src/wherecode.c cf885ea2d439af9827c5cbab7d4c12be5c079439b7bd12e97151ccfe088c13c0
+F src/wherecode.c e1131fe94c8728cbecc707f6455afbda9418896497bdca2d49a04ce6c57999f6
 F src/whereexpr.c 5cce1fd11876086890a27c05e0cb75ca97ba64ba6984f72154039f1cfd2e69cc
 F src/window.c 07e1c15081a735750218185c6b17053c87ecb764d06ab2c0a1ce568a2b4688e5
 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
-F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd
+F test/affinity2.test 34f2cf88e2a08d7a54a1fa2c9773ba81bf8b8216c0895e476118a1285540ee71
 F test/affinity3.test 6a101af2fc945ce2912f6fe54dd646018551710d
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/aggnested.test 18b00de006597e960a6b27ccec51474ac66cf1070a87c1933e5694dc02190ef1
@@ -1836,7 +1836,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P e2c6fed8f84929ed51a4e876bb09c85ac4b86a2e4cf0832a7da724bb9f4df5bf
-R 8b1ae3c95bd6ffc47e9182b0d67348c9
-U mistachkin
-Z 2a3c93f956b1ecd418b937639070a999
+P ec4c63e00c957f98d61ddc1b9d20406c7e1072d6ab0c12ac6939db6c63d90cb8
+R 95e8d7b4c9783731533e987936fe1358
+U dan
+Z 9e91c8360eb84da6700bb773b0dba23e
index 1d741309c7e1a2f011f6d63b645fb0d4b6edb243..9ea5046c2d1704391c2acbf6c1e9d230e1613e63 100644 (file)
@@ -1 +1 @@
-ec4c63e00c957f98d61ddc1b9d20406c7e1072d6ab0c12ac6939db6c63d90cb8
\ No newline at end of file
+511da0815673ca4a176aa61dc23a8231b2ab77e8363fc184a78b6e17dba64d49
\ No newline at end of file
index c781b06c15b0827df5c5e01ca1e09d5e5e794c49..934e3e2e8f08d7ef768142d1ed807f58bf766668 100644 (file)
@@ -1117,6 +1117,7 @@ typedef struct IdxExprTrans {
 static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
   IdxExprTrans *pX = p->u.pIdxTrans;
   if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
+    pExpr->affExpr = sqlite3ExprAffinity(pExpr);
     pExpr->op = TK_COLUMN;
     pExpr->iTable = pX->iIdxCur;
     pExpr->iColumn = pX->iIdxCol;
index 9838bd660acddd9dd1684f92b564b4f133875c3b..033c90f448dd36b80dda2b88f97856e5f1ac9d6f 100644 (file)
@@ -14,6 +14,7 @@
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
+set testprefix affinity2
 
 do_execsql_test affinity2-100 {
   CREATE TABLE t1(
@@ -58,4 +59,30 @@ do_execsql_test affinity2-300 {
   SELECT rowid, xt==+xi, xt==xi, xt==xb FROM t1 ORDER BY rowid;
 } {1 1 1 0 2 1 1 1 3 0 1 1}
 
+#-------------------------------------------------------------------------
+do_execsql_test 400 {
+  CREATE TABLE ttt(c0, c1);
+  CREATE INDEX ii ON ttt(CAST(c0 AS NUMERIC)); 
+  INSERT INTO ttt VALUES('abc', '-1');
+}
+do_execsql_test 410 {
+  SELECT * FROM ttt WHERE CAST(c0 AS NUMERIC) > c1 GROUP BY rowid; 
+} {abc -1}
+do_execsql_test 420 {
+  SELECT * FROM ttt INDEXED BY ii WHERE CAST(c0 AS NUMERIC) > c1 GROUP BY rowid;
+} {abc -1}
+
+do_execsql_test 430 {
+  CREATE TABLE t3(a, b, c INTEGER);
+  CREATE INDEX t3ac ON t3(a, c-1);
+  INSERT INTO t3 VALUES(1, 1, 1);
+  INSERT INTO t3 VALUES(2, 1, 0);
+  INSERT INTO t3 VALUES(3, 1, 1);
+  INSERT INTO t3 VALUES(4, 1, 0);
+  INSERT INTO t3 VALUES(5, 1, 1);
+}
+do_execsql_test 440 {
+  SELECT * FROM t3 WHERE c='0' ORDER BY a;
+} {2 1 0 4 1 0}
+
 finish_test