]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
New options for vt02.c that allow tests to configure it to partially
authordrh <>
Thu, 18 Dec 2025 16:14:38 +0000 (16:14 +0000)
committerdrh <>
Thu, 18 Dec 2025 16:14:38 +0000 (16:14 +0000)
de-duplicate a DISTINCT query.

FossilOrigin-Name: 1c65bb6e5d92cf39c409b7f870253571ec96b48abf87e5ed931cabd86f582069

manifest
manifest.uuid
test/vt02.c

index 0b8dc53bafa2120dd5765b716b78d140995b9e78..577af38117df04dae4d4bccb67dfb8a65fef5981 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Improve\stests\sin\sbestindexF.test.\sNo\schanges\sto\snon-test\scode.
-D 2025-12-18T16:05:05.184
+C New\soptions\sfor\svt02.c\sthat\sallow\stests\sto\sconfigure\sit\sto\spartially\nde-duplicate\sa\sDISTINCT\squery.
+D 2025-12-18T16:14:38.572
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -1948,7 +1948,7 @@ F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661
 F test/view.test 3c23d7a068e9e4a0c4e6907498042772adea725f0630c3d9638ffd4e5a08b92b
 F test/view2.test db32c8138b5b556f610b35dfddd38c5a58a292f07fda5281eedb0851b2672679
 F test/view3.test ad8a8290ee2b55ff6ce66c9ef1ce3f1e47926273a3814e1c425293e128a95456
-F test/vt02.c e2eb2e576567bba5c0f7bd7fe1a267fe566f1422a55fcff6dda02012159ec95d
+F test/vt02.c 91f2643dce0385300294cb2e78b459d038a3f4b095ab5031926742e8871487d4
 F test/vt100-a.sql a3e188a118ca78c08b41681a4db6d0f353e554ceb33f1573b1872d16e2d30596
 F test/vtab1.test 09a72330d0f31eda2ffaa828b06a6b917fb86250ee72de0301570af725774c07
 F test/vtab2.test 14d4ab26cee13ba6cf5c5601b158e4f57552d3b055cdd9406cf7f711e9c84082
@@ -2187,8 +2187,8 @@ F tool/version-info.c 33d0390ef484b3b1cb685d59362be891ea162123cea181cb8e6d2cf6dd
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 612c1ece6752e3318fc688717ad6a82219b85df7d32e4e07dbc2f361a5aeeee4
-R 580ea8657cb3efb5b82ff2a1e13c7fc2
-U dan
-Z 99a67f6205f5b3113357bf79d420e775
+P 347d4d34c1815827e7049e57830c1fff67f6eb16ae5cc00839e35d94bac81e92
+R 29e510d0a5b9184871ac0c9974760fc9
+U drh
+Z 011846103a1c6bd79a9c9fff8a8c2bf0
 # Remove this line to create a well-formed Fossil manifest.
index fc5a989e4c3a0dd2611b236eacb6d04e9790c475..b1a23da37995bef696a04f542199e94ff9a378c5 100644 (file)
@@ -1 +1 @@
-347d4d34c1815827e7049e57830c1fff67f6eb16ae5cc00839e35d94bac81e92
+1c65bb6e5d92cf39c409b7f870253571ec96b48abf87e5ed931cabd86f582069
index 4d1fdbae42222d02e7ed4b6328702083eef8f1a7..1675c26adac995cd959e3da5e485a051c1a8b3da 100644 (file)
 **                      vector of results sent to xFilter.  Only the first
 **                      few are used, as required by idxNum.
 **
+**       0x80           If sqlite3_vtab_distinct() says that duplicate rows
+**                      may be omitted (values 2 or 3), then maybe omit
+**                      some but not all of the duplicate rows.
+**
+**       0x100          Do not omit any duplicate rows even if
+**                      sqlite3_vtab_distinct() says that is ok to do.
+**
 ** Because these flags take effect during xBestIndex, the RHS of the
 ** flag= constraint must be accessible.  In other words, the RHS of flag=
 ** needs to be an integer literal, not another column of a join or a
@@ -215,6 +222,8 @@ struct vt02_vtab {
 #define VT02_NO_OFFSET      0x0004  /* Omit the offset optimization */
 #define VT02_ALLOC_IDXSTR   0x0008  /* Alloate an idxStr */
 #define VT02_BAD_IDXNUM     0x0010  /* Generate an invalid idxNum */
+#define VT02_PARTIAL_DEDUP  0x0080  /* Omit some but not all duplicate rows */
+#define VT02_NO_DEDUP       0x0100  /* Include all duplicate rows */
 
 /*
 ** A cursor
@@ -905,18 +914,21 @@ static int vt02BestIndex(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
       }else if( nAsc==0 ){
         pInfo->idxNum += 1000;   /* Reverse output order */
       }
-      if( eDistinct==2 ){  /* DISTINCT */
+      if( eDistinct>=2 && (flags & VT02_NO_DEDUP)!=0 ){
+        eDistinct = 1;
+      }
+      if( eDistinct>=2 ){  /* DISTINCT or (DISTINCT and ORDER BY) */
         if( x==0x02 ){
           /* DISTINCT A */
-          pInfo->idxNum += 30;
+          pInfo->idxNum += (flags & VT02_PARTIAL_DEDUP)!=0 ? 20 : 30;
           pInfo->orderByConsumed = 1;
         }else if( x==0x06 ){
           /* DISTINCT A,B */
-          pInfo->idxNum += 20;
+          pInfo->idxNum += (flags & VT02_PARTIAL_DEDUP)!=0 ? 10 : 20;
           pInfo->orderByConsumed = 1;
         }else if( x==0x0e ){
           /* DISTINCT A,B,C */
-          pInfo->idxNum += 10;
+          pInfo->idxNum += (flags & VT02_PARTIAL_DEDUP)!=0 ? 0 : 10;
           pInfo->orderByConsumed = 1;
         }else if( x & 0x01 ){
           /* DISTINCT X */
@@ -925,7 +937,7 @@ static int vt02BestIndex(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
           /* DISTINCT A,B,C,D */
           pInfo->orderByConsumed = 1;
         }
-      }else if( eDistinct>=1 ){  /* GROUP BY or (DISTINCT and ORDER BY) */
+      }else{  /* GROUP BY */
         if( x==0x02 ){
           /* GROUP BY A */
           pInfo->orderByConsumed = 1;