From: dan Date: Tue, 9 Mar 2021 16:47:33 +0000 (+0000) Subject: Add missing comment to new routine in select.c. X-Git-Tag: version-3.36.0~289^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=96ecb7b00425ae7f809dd356b17f72e6689eb99a;p=thirdparty%2Fsqlite.git Add missing comment to new routine in select.c. FossilOrigin-Name: ef2f0cf21ba61bdd29e09cf41b012a2d757683f524a252f0af7dfee7df1a1a0f --- diff --git a/manifest b/manifest index 9be753e63b..1e2167b501 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Experimental\soptimization\sfor\sdistinct\saggregates\s(e.g.\s"SELECT\scount(DISTINCT\s) ..."). 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: +** +** WHERE_DISTINCT_UNORDERED/WHERE_DISTINCT_NOOP: +** The ephemeral cursor table is queries 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. +** +** 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 +** registers are compared to previous row. If they match, the new row +** is not distinct and control jumps to VM address addrRepeat. Otherwise, +** the VM program proceeds with processing the new row. +** +** WHERE_DISTINCT_UNIQUE: +** In this case it has already been determined that the rows are distinct. +** No special action is required. +** +** Parameter pEList is the list of expressions used to generated the +** contents of each row. It is used by this routine to determine (a) +** how many elements there are in the array of registers and (b) the +** collation sequences that should be used for the comparisons if +** eTnctType is WHERE_DISTINCT_ORDERED. */ static void codeDistinct( - Parse *pParse, /* Parsing and code generating context */ - int iTab, /* A sorting index used to test for distinctness */ - int addrRepeat, /* Jump to here if not distinct */ - int N, /* Number of elements */ - int iMem /* First element */ -){ - Vdbe *v; - int r1; - - v = pParse->pVdbe; - r1 = sqlite3GetTempReg(pParse); - sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v); - sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1); - sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r1, iMem, N); - sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); - sqlite3ReleaseTempReg(pParse, r1); -} -#endif - -static void codeDistinct2( Parse *pParse, /* Parsing and code generating context */ int eTnctType, /* WHERE_DISTINCT_* value */ int iTab, /* A sorting index used to test for distinctness */ @@ -1087,7 +1088,7 @@ static void selectInnerLoop( */ if( hasDistinct ){ assert( nResultCol==p->pEList->nExpr ); - codeDistinct2(pParse, pDistinct->eTnctType, pDistinct->tabTnct, + codeDistinct(pParse, pDistinct->eTnctType, pDistinct->tabTnct, pDistinct->addrTnct, iContinue, p->pEList, regResult); if( pSort==0 ){ codeOffset(v, p->iOffset, iContinue); @@ -5748,7 +5749,7 @@ static void updateAccumulator( } testcase( nArg==0 ); /* Error condition */ testcase( nArg>1 ); /* Also an error */ - codeDistinct2(pParse, eDistinctType, pF->iDistinct, pF->iDistAddr, + codeDistinct(pParse, eDistinctType, pF->iDistinct, pF->iDistAddr, addrNext, pList, regAgg); } if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){