1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-11 01:42:22 +03:00

In the parse tree, combine LIMIT and OFFSET into a single expression rooted

on a TK_LIMIT node, for a small code size reduction and performance increase,
and a reduction in code complexity.

FossilOrigin-Name: 3925facd942c9df663f9b29b1e6f94f6be14af8c2b99eb691bfc836b4c220826
This commit is contained in:
drh
2017-11-14 23:48:23 +00:00
parent 65efeaca83
commit 8c0833fb21
15 changed files with 92 additions and 140 deletions

View File

@@ -92,7 +92,6 @@ void sqlite3MaterializeView(
Expr *pWhere, /* Optional WHERE clause to be added */
ExprList *pOrderBy, /* Optional ORDER BY clause */
Expr *pLimit, /* Optional LIMIT clause */
Expr *pOffset, /* Optional OFFSET clause */
int iCur /* Cursor number for ephemeral table */
){
SelectDest dest;
@@ -110,7 +109,7 @@ void sqlite3MaterializeView(
assert( pFrom->a[0].pUsing==0 );
}
pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, pOrderBy,
SF_IncludeHidden, pLimit, pOffset);
SF_IncludeHidden, pLimit);
sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur);
sqlite3Select(pParse, pSel, &dest);
sqlite3SelectDelete(db, pSel);
@@ -132,7 +131,6 @@ Expr *sqlite3LimitWhere(
Expr *pWhere, /* The WHERE clause. May be null */
ExprList *pOrderBy, /* The ORDER BY clause. May be null */
Expr *pLimit, /* The LIMIT clause. May be null */
Expr *pOffset, /* The OFFSET clause. May be null */
char *zStmtType /* Either DELETE or UPDATE. For err msgs. */
){
sqlite3 *db = pParse->db;
@@ -149,8 +147,6 @@ Expr *sqlite3LimitWhere(
sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on %s", zStmtType);
sqlite3ExprDelete(pParse->db, pWhere);
sqlite3ExprListDelete(pParse->db, pOrderBy);
sqlite3ExprDelete(pParse->db, pLimit);
sqlite3ExprDelete(pParse->db, pOffset);
return 0;
}
@@ -158,8 +154,6 @@ Expr *sqlite3LimitWhere(
** is a limit/offset term to enforce.
*/
if( pLimit == 0 ) {
/* if pLimit is null, pOffset will always be null as well. */
assert( pOffset == 0 );
return pWhere;
}
@@ -206,7 +200,7 @@ Expr *sqlite3LimitWhere(
/* generate the SELECT expression tree. */
pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0,
pOrderBy,0,pLimit,pOffset
pOrderBy,0,pLimit
);
/* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
@@ -229,8 +223,7 @@ void sqlite3DeleteFrom(
SrcList *pTabList, /* The table from which we should delete things */
Expr *pWhere, /* The WHERE clause. May be null */
ExprList *pOrderBy, /* ORDER BY clause. May be null */
Expr *pLimit, /* LIMIT clause. May be null */
Expr *pOffset /* OFFSET clause. May be null */
Expr *pLimit /* LIMIT clause. May be null */
){
Vdbe *v; /* The virtual database engine */
Table *pTab; /* The table from which records will be deleted */
@@ -303,10 +296,10 @@ void sqlite3DeleteFrom(
#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
if( !isView ){
pWhere = sqlite3LimitWhere(
pParse, pTabList, pWhere, pOrderBy, pLimit, pOffset, "DELETE"
pParse, pTabList, pWhere, pOrderBy, pLimit, "DELETE"
);
pOrderBy = 0;
pLimit = pOffset = 0;
pLimit = 0;
}
#endif
@@ -358,11 +351,11 @@ void sqlite3DeleteFrom(
#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
if( isView ){
sqlite3MaterializeView(pParse, pTab,
pWhere, pOrderBy, pLimit, pOffset, iTabCur
pWhere, pOrderBy, pLimit, iTabCur
);
iDataCur = iIdxCur = iTabCur;
pOrderBy = 0;
pLimit = pOffset = 0;
pLimit = 0;
}
#endif
@@ -609,7 +602,6 @@ delete_from_cleanup:
#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
sqlite3ExprListDelete(db, pOrderBy);
sqlite3ExprDelete(db, pLimit);
sqlite3ExprDelete(db, pOffset);
#endif
sqlite3DbFree(db, aToOpen);
return;