]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix a crash in new code on this branch.
authordan <Dan Kennedy>
Fri, 12 Mar 2021 21:09:20 +0000 (21:09 +0000)
committerdan <Dan Kennedy>
Fri, 12 Mar 2021 21:09:20 +0000 (21:09 +0000)
FossilOrigin-Name: c05ed2a8a9c4975c69bdfa733598ed90c1509d52b3c39dedbd829ab148777e1d

manifest
manifest.uuid
src/select.c

index 8dc150ac085533a24f76b4eb68bb7805bc3e71ea..777c57add8eca8dceb41829a2aa1ade4c45befac 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Merge\slatest\strunk\schanges\sinto\sthis\sbranch.
-D 2021-03-12T18:33:55.409
+C Fix\sa\scrash\sin\snew\scode\son\sthis\sbranch.
+D 2021-03-12T21:09:20.890
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -542,7 +542,7 @@ F src/printf.c 2b03a80d7c11bb422115dca175a18bf430e9c9dbaa0eee63b758f0c022f8f34f
 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
 F src/resolve.c d95db73d3e6a5c689e5f6604b4d2521350e45f2a0f0f84f5a2dc2bfee56580a0
 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
-F src/select.c bc60b2b50953c73f743bf88e01c389a426a02f01c4744ffe21020476908a12e3
+F src/select.c 05c83f086a7da99478a53a5355ae0d9fd5edd3aeaa079c814205211ac58c21e1
 F src/shell.c.in 35adf1212d759069b00e468a9304a05a67710c8f8f50e7312335e23cac985d8c
 F src/sqlite.h.in 3426a080ea1f222a73e3bd91e7eacbd30570a0117c03d42c6dde606f33e5e318
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
@@ -1910,7 +1910,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 3bca003cd2b2cb38d4a4e2e5f673ee0ac05bfe31247ec09e7bd379b77a31b44c acd63062eb06748bfe9e4886639e4f2b54ea6a496a83f10716abbaba4115500b
-R 86fbe1c09f3de8e5e7b5e69edb87ebd0
+P 198bc510d64b5794559584ad5c9de41dc966dce4eb78be15b12adba43dfcb639
+R 6377899be744d0cc8507f339ce2d0263
 U dan
-Z b671b123ff2e4c1e64c0384e9dd5309a
+Z baf0281e2435d9e0d6e51472154aad62
index 24c87ad4b910ce172179f90b0094aa5d47184ffc..4bc513c98f055299f56ab82dc96e89575ba4af51 100644 (file)
@@ -1 +1 @@
-198bc510d64b5794559584ad5c9de41dc966dce4eb78be15b12adba43dfcb639
\ No newline at end of file
+c05ed2a8a9c4975c69bdfa733598ed90c1509d52b3c39dedbd829ab148777e1d
\ No newline at end of file
index 43ad2784e9cd58987d4865bb053bcf9b4b082b4a..a2a979b5ea61acfe769416d23f2a3a89bc2081d8 100644 (file)
@@ -743,17 +743,20 @@ static void codeOffset(
 /*
 ** Add code that will check to make sure the array of registers starting at
 ** iMem form a distinct entry. This is used by both "SELECT DISTINCT ..." and
-** distinct aggregates ("SELECT count(DISTINCT <expr>) ..."). Parameter iTab is
-** the cursor number of an ephemeral table opened by instruction iTabAddr for
-** the code generated by this routine to use. There are three strategies, based
-** on the value of parameter eTnctType:
+** distinct aggregates ("SELECT count(DISTINCT <expr>) ..."). Three strategies
+** are available. Which is used depends on the value of parameter eTnctType,
+** as follows:
 **
 **   WHERE_DISTINCT_UNORDERED/WHERE_DISTINCT_NOOP:
+**     Parameter iTab is the cursor number of an ephemeral table that must
+**     be opened before the VM code generated by this routine is executed.
 **     The ephemeral cursor table is queried for a record identical to the
 **     record formed by the current array of registers. If one is found,
 **     jump to VM address addrRepeat. Otherwise, insert a new record into
 **     the ephemeral cursor and proceed.
 **
+**     The returned value in this case is a copy of parameter iTab.
+**
 **   WHERE_DISTINCT_ORDERED:
 **     In this case rows are being delivered sorted order sorted. The ephermal
 **     table is not required in this case. Instead, the current set of 
@@ -761,9 +764,14 @@ static void codeOffset(
 **     is not distinct and control jumps to VM address addrRepeat. Otherwise,
 **     the VM program proceeds with processing the new row.
 **
+**     The returned value in this case is the register number of the first
+**     in an array of registers used to store the previous result row so that
+**     it can be compared to the next. The caller must ensure that this cell
+**     is initialized to NULL and has the "clear" flag set.
+**
 **   WHERE_DISTINCT_UNIQUE:
 **     In this case it has already been determined that the rows are distinct.
-**     No special action is required.
+**     No special action is required. The return value is always zero.
 **
 ** Parameter pEList is the list of expressions used to generated the 
 ** contents of each row. It is used by this routine to determine (a) 
@@ -832,21 +840,42 @@ static int codeDistinct(
   return iRet;
 }
 
+/*
+** A call to this function must be made for each call to codeDistinct().
+** Parameter is passed the value returned by that call to codeDistinct(),
+** and iOpenEphAddr the address of the instruction used to open the
+** ephemeral table (that may be) used by codeDistinct().
+**
+** Argument eTnctType is passed the strategy to be used for any DISTINCT
+** operation, as returned by sqlite3WhereIsDistinct(). If the strategy
+** is WHERE_DISTINCT_NOOP or WHERE_DISTINCT_UNORDERED, this function is
+** a no-op. Otherwise:
+**
+**   WHERE_DISTINCT_UNIQUE:
+**     In this case the ephemeral table is not required. So instruction
+**     iOpenEphAddr is replaced by an OP_Noop.
+**
+**   WHERE_DISTINCT_ORDERED:
+**     In this case the ephemeral table is not required. The instruction
+**     iOpenEphAddr is replaced by an OP_Null instruction to set register
+**     iVal to a NULL value with the "clear" flag set (see comments above
+**     codeDistinct() for details).
+*/
 static void fixDistinctOpenEph(
   Parse *pParse,     /* Parsing and code generating context */
   int eTnctType,     /* WHERE_DISTINCT_* value */
   int iVal,          /* Value returned by codeDistinct() */
-  int iTabAddr       /* Address of OP_OpenEphemeral instruction for iTab */
+  int iOpenEphAddr   /* Address of OP_OpenEphemeral instruction for iTab */
 ){
   if( eTnctType==WHERE_DISTINCT_UNIQUE || eTnctType==WHERE_DISTINCT_ORDERED ){
     Vdbe *v = pParse->pVdbe;
-    sqlite3VdbeChangeToNoop(v, iTabAddr);
+    sqlite3VdbeChangeToNoop(v, iOpenEphAddr);
     if( eTnctType==WHERE_DISTINCT_ORDERED ){
       /* Change the OP_OpenEphemeral to an OP_Null that sets the MEM_Cleared 
       ** bit on the first register of the previous value.  This will cause the
       ** OP_Ne added in codeDistinct() to always fail on the first iteration of
       ** the loop even if the first row is all NULLs.  */
-      VdbeOp *pOp = sqlite3VdbeGetOp(v, iTabAddr);
+      VdbeOp *pOp = sqlite3VdbeGetOp(v, iOpenEphAddr);
       pOp->opcode = OP_Null;
       pOp->p1 = 1;
       pOp->p2 = iVal;
@@ -6848,6 +6877,7 @@ int sqlite3Select(
           WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0
       );
       if( pWInfo==0 ) goto select_end;
+      eDist = sqlite3WhereIsDistinct(pWInfo);
       SELECTTRACE(1,pParse,p,("WhereBegin returns\n"));
       if( sqlite3WhereIsOrdered(pWInfo)==pGroupBy->nExpr ){
         /* The optimizer is able to deliver rows in group by order so
@@ -6965,7 +6995,6 @@ int sqlite3Select(
       ** the current row
       */
       sqlite3VdbeJumpHere(v, addr1);
-      eDist = sqlite3WhereIsDistinct(pWInfo);
       updateAccumulator(pParse, iUseFlag, pAggInfo, eDist);
       sqlite3VdbeAddOp2(v, OP_Integer, 1, iUseFlag);
       VdbeComment((v, "indicate data in accumulator"));