1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Rework the FILTER clause implementation to share more code with window functions.

FossilOrigin-Name: 5dac8c38dfc3f41c5c8fb49ca35de7fd1b21f269d72e8ba6ba59ed0a4030a54d
This commit is contained in:
dan
2019-07-13 16:22:50 +00:00
parent 648d629953
commit 4f9adee289
10 changed files with 116 additions and 119 deletions

View File

@@ -1193,25 +1193,20 @@ void sqlite3WindowChain(Parse *pParse, Window *pWin, Window *pList){
/*
** Attach window object pWin to expression p.
*/
void sqlite3WindowAttach(Parse *pParse, Expr *p, Expr *pFilter, Window *pWin){
void sqlite3WindowAttach(Parse *pParse, Expr *p, Window *pWin){
if( p ){
assert( p->op==TK_FUNCTION );
if( pWin ){
p->y.pWin = pWin;
ExprSetProperty(p, EP_WinFunc);
pWin->pOwner = p;
if( p->flags & EP_Distinct ){
sqlite3ErrorMsg(pParse,
"DISTINCT is not supported for window functions");
}
pWin->pFilter = pFilter;
}else if( pFilter ){
p->y.pFilter = pFilter;
ExprSetProperty(p, EP_Filter);
assert( pWin );
p->y.pWin = pWin;
ExprSetProperty(p, EP_WinFunc);
pWin->pOwner = p;
if( (p->flags & EP_Distinct) && pWin->eFrmType!=TK_FILTER ){
sqlite3ErrorMsg(pParse,
"DISTINCT is not supported for window functions"
);
}
}else{
sqlite3WindowDelete(pParse->db, pWin);
sqlite3ExprDelete(pParse->db, pFilter);
}
}
@@ -1219,7 +1214,7 @@ void sqlite3WindowAttach(Parse *pParse, Expr *p, Expr *pFilter, Window *pWin){
** Return 0 if the two window objects are identical, or non-zero otherwise.
** Identical window objects can be processed in a single scan.
*/
int sqlite3WindowCompare(Parse *pParse, Window *p1, Window *p2){
int sqlite3WindowCompare(Parse *pParse, Window *p1, Window *p2, int bFilter){
if( p1->eFrmType!=p2->eFrmType ) return 1;
if( p1->eStart!=p2->eStart ) return 1;
if( p1->eEnd!=p2->eEnd ) return 1;
@@ -1228,6 +1223,9 @@ int sqlite3WindowCompare(Parse *pParse, Window *p1, Window *p2){
if( sqlite3ExprCompare(pParse, p1->pEnd, p2->pEnd, -1) ) return 1;
if( sqlite3ExprListCompare(p1->pPartition, p2->pPartition, -1) ) return 1;
if( sqlite3ExprListCompare(p1->pOrderBy, p2->pOrderBy, -1) ) return 1;
if( bFilter ){
if( sqlite3ExprCompare(pParse, p1->pFilter, p2->pFilter, -1) ) return 1;
}
return 0;
}