Skip to content

Commit

Permalink
sql: drop useless legacy Cursor hints
Browse files Browse the repository at this point in the history
Deleted BTREE_BULKLOAD and OPFLAG_BULKCSR as there become
useless since btree.c was dropped as a part of #2419.
Removed SQLITE_ENABLE_CURSOR_HINTS sections as this code
has never been in use.
Start use OPFLAG_SEEKEQ instead of equal BTREE_SEEK_EQ as
this macro name has no sense since no btree present in SQL.

Resolves #3121.
  • Loading branch information
kshcherbatov committed Jun 9, 2018
1 parent 42ab6d4 commit 427c2b9
Show file tree
Hide file tree
Showing 12 changed files with 11 additions and 440 deletions.
4 changes: 2 additions & 2 deletions src/box/sql.c
Expand Up @@ -292,12 +292,12 @@ int tarantoolSqlite3MovetoUnpacked(BtCursor *pCur, UnpackedRecord *pIdxKey,
res_success = -1; /* item<key */
break;
case OP_SeekLE:
pCur->iter_type = (pCur->hints & BTREE_SEEK_EQ) ?
pCur->iter_type = (pCur->hints & OPFLAG_SEEKEQ) ?
ITER_REQ : ITER_LE;
res_success = 0; /* item==key */
break;
case OP_SeekGE:
pCur->iter_type = (pCur->hints & BTREE_SEEK_EQ) ?
pCur->iter_type = (pCur->hints & OPFLAG_SEEKEQ) ?
ITER_EQ : ITER_GE;
res_success = 0; /* item==key */
break;
Expand Down
4 changes: 1 addition & 3 deletions src/box/sql/build.c
Expand Up @@ -2676,9 +2676,7 @@ sqlite3RefillIndex(Parse * pParse, Index * pIndex, int memRootPage)
sqlite3VdbeAddOp2(v, OP_Clear, SQLITE_PAGENO_TO_SPACEID(tnum),
0);
emit_open_cursor(pParse, iIdx, tnum);
sqlite3VdbeChangeP5(v,
OPFLAG_BULKCSR | ((memRootPage >= 0) ?
OPFLAG_P2ISREG : 0));
sqlite3VdbeChangeP5(v, memRootPage >= 0 ? OPFLAG_P2ISREG : 0);

addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
VdbeCoverage(v);
Expand Down
2 changes: 1 addition & 1 deletion src/box/sql/cursor.c
Expand Up @@ -53,7 +53,7 @@ sql_cursor_cleanup(struct BtCursor *cursor)
void
sqlite3CursorHintFlags(BtCursor * pCur, unsigned x)
{
assert(x == BTREE_SEEK_EQ || x == BTREE_BULKLOAD || x == 0);
assert(x == OPFLAG_SEEKEQ || x == 0);
pCur->hints = x;
}

Expand Down
16 changes: 0 additions & 16 deletions src/box/sql/cursor.h
Expand Up @@ -34,22 +34,6 @@

typedef struct BtCursor BtCursor;

/*
* Values that may be OR'd together to form the argument to the
* BTREE_HINT_FLAGS hint for sqlite3BtreeCursorHint():
*
* The BTREE_BULKLOAD flag is set on index cursors when the index is going
* to be filled with content that is already in sorted order.
*
* The BTREE_SEEK_EQ flag is set on cursors that will get OP_SeekGE or
* OP_SeekLE opcodes for a range search, but where the range of entries
* selected will all have the same key. In other words, the cursor will
* be used only for equality key searches.
*
*/
#define BTREE_BULKLOAD 0x00000001 /* Used to full index in sorted order */
#define BTREE_SEEK_EQ 0x00000002 /* EQ seeks only - no range seeks */

/*
* A cursor contains a particular entry either from Tarantrool or
* Sorter. Tarantool cursor is able to point to ordinary table or
Expand Down
18 changes: 0 additions & 18 deletions src/box/sql/expr.c
Expand Up @@ -2000,24 +2000,6 @@ sqlite3ExprIsConstantOrFunction(Expr * p, u8 isInit)
return exprIsConst(p, 4 + isInit, 0);
}

#ifdef SQLITE_ENABLE_CURSOR_HINTS
/*
* Walk an expression tree. Return 1 if the expression contains a
* subquery of some kind. Return 0 if there are no subqueries.
*/
int
sqlite3ExprContainsSubquery(Expr * p)
{
Walker w;
memset(&w, 0, sizeof(w));
w.eCode = 1;
w.xExprCallback = sqlite3ExprWalkNoop;
w.xSelectCallback = selectNodeIsConstant;
sqlite3WalkExpr(&w, p);
return w.eCode == 0;
}
#endif

/*
* If the expression p codes a constant integer that is small enough
* to fit in a 32-bit integer, return 1 and put the value of the integer
Expand Down
1 change: 0 additions & 1 deletion src/box/sql/insert.c
Expand Up @@ -1963,7 +1963,6 @@ xferOptimization(Parse * pParse, /* Parser context */
VdbeComment((v, "%s", pSrcIdx->zName));
emit_open_cursor(pParse, iDest, pDestIdx->tnum);
sql_vdbe_set_p4_key_def(pParse, pDestIdx);
sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
VdbeComment((v, "%s", pDestIdx->zName));
addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
VdbeCoverage(v);
Expand Down
7 changes: 0 additions & 7 deletions src/box/sql/sqliteInt.h
Expand Up @@ -2978,8 +2978,6 @@ struct Parse {
* Value constraints (enforced via assert()):
* OPFLAG_LENGTHARG == SQLITE_FUNC_LENGTH
* OPFLAG_TYPEOFARG == SQLITE_FUNC_TYPEOF
* OPFLAG_BULKCSR == BTREE_BULKLOAD
* OPFLAG_SEEKEQ == BTREE_SEEK_EQ
* OPFLAG_FORDELETE == BTREE_FORDELETE
* OPFLAG_SAVEPOSITION == BTREE_SAVEPOSITION
* OPFLAG_AUXDELETE == BTREE_AUXDELETE
Expand All @@ -2995,7 +2993,6 @@ struct Parse {
#endif
#define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */
#define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */
#define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */
#define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */
#define OPFLAG_FORDELETE 0x08 /* OP_Open should use BTREE_FORDELETE */
#define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */
Expand Down Expand Up @@ -3239,7 +3236,6 @@ struct Walker {
int iCur; /* A cursor number */
SrcList *pSrcList; /* FROM clause */
struct SrcCount *pSrcCount; /* Counting column references */
struct CCurHint *pCCurHint; /* Used by codeCursorHint() */
int *aiCol; /* array of column indexes */
struct IdxCover *pIdxCover; /* Check for index coverage */
/** Space definition. */
Expand Down Expand Up @@ -3834,9 +3830,6 @@ int sqlite3ExprIsConstant(Expr *);
int sqlite3ExprIsConstantNotJoin(Expr *);
int sqlite3ExprIsConstantOrFunction(Expr *, u8);
int sqlite3ExprIsTableConstant(Expr *, int);
#ifdef SQLITE_ENABLE_CURSOR_HINTS
int sqlite3ExprContainsSubquery(Expr *);
#endif
int sqlite3ExprIsInteger(Expr *, int *);
int sqlite3ExprCanBeNull(const Expr *);
int sqlite3ExprNeedsNoAffinityChange(const Expr *, char);
Expand Down
19 changes: 7 additions & 12 deletions src/box/sql/vdbe.c
Expand Up @@ -3206,14 +3206,7 @@ case OP_OpenWrite:
pCur->key_def = index->def->key_def;

open_cursor_set_hints:
assert(OPFLAG_BULKCSR==BTREE_BULKLOAD);
assert(OPFLAG_SEEKEQ==BTREE_SEEK_EQ);
testcase( pOp->p5 & OPFLAG_BULKCSR);
#ifdef SQLITE_ENABLE_CURSOR_HINTS
testcase( pOp->p2 & OPFLAG_SEEKEQ);
#endif
sqlite3CursorHintFlags(pCur->uc.pCursor,
(pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ)));
sqlite3CursorHintFlags(pCur->uc.pCursor, pOp->p5 & OPFLAG_SEEKEQ);
if (rc) goto abort_due_to_error;
break;
}
Expand Down Expand Up @@ -3527,11 +3520,13 @@ case OP_SeekGT: { /* jump, in3 */
}
}
}
/* For a cursor with the BTREE_SEEK_EQ hint, only the OP_SeekGE and
* OP_SeekLE opcodes are allowed, and these must be immediately followed
* by an OP_IdxGT or OP_IdxLT opcode, respectively, with the same key.
/*
* For a cursor with the OPFLAG_SEEKEQ hint, only the
* OP_SeekGE and OP_SeekLE opcodes are allowed, and these
* must be immediately followed by an OP_IdxGT or
* OP_IdxLT opcode, respectively, with the same key.
*/
if (sqlite3CursorHasHint(pC->uc.pCursor, BTREE_SEEK_EQ)) {
if (sqlite3CursorHasHint(pC->uc.pCursor, OPFLAG_SEEKEQ) != 0) {
eqOnly = 1;
assert(pOp->opcode==OP_SeekGE || pOp->opcode==OP_SeekLE);
assert(pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT);
Expand Down
3 changes: 0 additions & 3 deletions src/box/sql/vdbe.h
Expand Up @@ -80,9 +80,6 @@ struct VdbeOp {
int *ai; /* Used when p4type is P4_INTARRAY */
SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */
Index *pIndex; /* Used when p4type is P4_INDEX */
#ifdef SQLITE_ENABLE_CURSOR_HINTS
Expr *pExpr; /* Used when p4type is P4_EXPR */
#endif
int (*xAdvance) (BtCursor *, int *);
/** Used when p4type is P4_KEYDEF. */
struct key_def *key_def;
Expand Down
133 changes: 0 additions & 133 deletions src/box/sql/vdbeaux.c
Expand Up @@ -972,12 +972,6 @@ freeP4(sqlite3 * db, int p4type, void *p4)
case P4_KEYDEF:
key_def_delete(p4);
break;
#ifdef SQLITE_ENABLE_CURSOR_HINTS
case P4_EXPR:{
sqlite3ExprDelete(db, (Expr *) p4);
break;
}
#endif
case P4_FUNCDEF:{
freeEphemeralFunction(db, (FuncDef *) p4);
break;
Expand Down Expand Up @@ -1389,127 +1383,6 @@ displayComment(const Op * pOp, /* The opcode to be commented */
}
#endif /* SQLITE_DEBUG */

#if defined(SQLITE_ENABLE_CURSOR_HINTS)
/*
* Translate the P4.pExpr value for an OP_CursorHint opcode into text
* that can be displayed in the P4 column of EXPLAIN output.
*/
static void
displayP4Expr(StrAccum * p, Expr * pExpr)
{
const char *zOp = 0;
switch (pExpr->op) {
case TK_STRING:
sqlite3XPrintf(p, "%Q", pExpr->u.zToken);
break;
case TK_INTEGER:
sqlite3XPrintf(p, "%d", pExpr->u.iValue);
break;
case TK_NULL:
sqlite3XPrintf(p, "NULL");
break;
case TK_REGISTER:{
sqlite3XPrintf(p, "r[%d]", pExpr->iTable);
break;
}
case TK_COLUMN:{
if (pExpr->iColumn < 0) {
sqlite3XPrintf(p, "rowid");
} else {
sqlite3XPrintf(p, "c%d", (int)pExpr->iColumn);
}
break;
}
case TK_LT:
zOp = "LT";
break;
case TK_LE:
zOp = "LE";
break;
case TK_GT:
zOp = "GT";
break;
case TK_GE:
zOp = "GE";
break;
case TK_NE:
zOp = "NE";
break;
case TK_EQ:
zOp = "EQ";
break;
case TK_AND:
zOp = "AND";
break;
case TK_OR:
zOp = "OR";
break;
case TK_PLUS:
zOp = "ADD";
break;
case TK_STAR:
zOp = "MUL";
break;
case TK_MINUS:
zOp = "SUB";
break;
case TK_REM:
zOp = "REM";
break;
case TK_BITAND:
zOp = "BITAND";
break;
case TK_BITOR:
zOp = "BITOR";
break;
case TK_SLASH:
zOp = "DIV";
break;
case TK_LSHIFT:
zOp = "LSHIFT";
break;
case TK_RSHIFT:
zOp = "RSHIFT";
break;
case TK_CONCAT:
zOp = "CONCAT";
break;
case TK_UMINUS:
zOp = "MINUS";
break;
case TK_UPLUS:
zOp = "PLUS";
break;
case TK_BITNOT:
zOp = "BITNOT";
break;
case TK_NOT:
zOp = "NOT";
break;
case TK_ISNULL:
zOp = "IS NULL";
break;
case TK_NOTNULL:
zOp = "NOT NULL";
break;

default:
sqlite3XPrintf(p, "%s", "expr");
break;
}

if (zOp) {
sqlite3XPrintf(p, "%s(", zOp);
displayP4Expr(p, pExpr->pLeft);
if (pExpr->pRight) {
sqlite3StrAccumAppend(p, ",", 1);
displayP4Expr(p, pExpr->pRight);
}
sqlite3StrAccumAppend(p, ")", 1);
}
}
#endif /* defined(SQLITE_ENABLE_CURSOR_HINTS) */

/*
* Compute a string that describes the P4 parameter for an opcode.
* Use zTemp for any required temporary buffer space.
Expand Down Expand Up @@ -1549,12 +1422,6 @@ displayP4(Op * pOp, char *zTemp, int nTemp)
}
break;
}
#ifdef SQLITE_ENABLE_CURSOR_HINTS
case P4_EXPR:{
displayP4Expr(&x, pOp->p4.pExpr);
break;
}
#endif
case P4_COLLSEQ:{
struct coll *pColl = pOp->p4.pColl;
if (pColl != NULL)
Expand Down
6 changes: 0 additions & 6 deletions src/box/sql/where.c
Expand Up @@ -4588,12 +4588,6 @@ sqlite3WhereBegin(Parse * pParse, /* The parser context */
&& pTab->nCol == BMS - 1);
testcase(pWInfo->eOnePass == ONEPASS_OFF
&& pTab->nCol == BMS);
#ifdef SQLITE_ENABLE_CURSOR_HINTS
if (pLoop->pIndex != 0) {
sqlite3VdbeChangeP5(v,
OPFLAG_SEEKEQ | bFordelete);
} else
#endif
{
sqlite3VdbeChangeP5(v, bFordelete);
}
Expand Down

0 comments on commit 427c2b9

Please sign in to comment.