From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 7D3332AD66 for ; Mon, 10 Sep 2018 17:43:35 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4zj5aRiN6_f4 for ; Mon, 10 Sep 2018 17:43:35 -0400 (EDT) Received: from smtp42.i.mail.ru (smtp42.i.mail.ru [94.100.177.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id B96392A6CE for ; Mon, 10 Sep 2018 17:43:34 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [tarantool-patches] Re: [PATCH v1 1/1] sql: support HAVING without GROUP BY clause From: "n.pettik" In-Reply-To: <077750b5-7433-6122-5df9-caa6ff462e70@tarantool.org> Date: Tue, 11 Sep 2018 00:43:26 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <00C60996-AB0B-4157-AF8D-DCD9B1F63D8D@tarantool.org> References: <16D5B1D2-2DBF-4BAE-9C5D-F23CCCE3723D@tarantool.org> <5f602cc5-9617-6717-c13a-4d5595c23422@tarantool.org> <99A1FBB4-3831-4BB6-A1D6-505D09F792AD@tarantool.org> <077750b5-7433-6122-5df9-caa6ff462e70@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Kirill Shcherbatov Still, other DBs (as usual I checked - Postgres, Oracle and DB2) process = this query as well: select 1 from t1 having min(a) > 0; In other words, not only aggregate can appear in SELECT args, but also constant literals. Semantically, it seems to be correct. Moreover, quieres like select date() from t1 having min(a) > 0; are valid too. What I mean is SELECT arguments must return single value for all rows in table (i.e. be single-group). =46rom the first sight, this problem is likely to be minor, but I guess we should implement correct behaviour as far as we are dealing with this issue right now. > diff --git a/src/box/sql/resolve.c b/src/box/sql/resolve.c > index 280ecd9..c38374d 100644 > --- a/src/box/sql/resolve.c > +++ b/src/box/sql/resolve.c > @@ -600,6 +600,8 @@ resolveExprStep(Walker * pWalker, Expr * pExpr) > /* A lone identifier is the name of a column. > */ > case TK_ID:{ > + if ((pNC->ncFlags & NC_AllowAgg) !=3D 0) > + pNC->ncFlags |=3D NC_HasUnaggregatedId; > return lookupName(pParse, 0, pExpr->u.zToken, = pNC, > pExpr); > } > @@ -1283,13 +1285,19 @@ resolveSelectStep(Walker * pWalker, Select * = p) > /* Set up the local name-context to pass to = sqlite3ResolveExprNames() to > * resolve the result-set expression list. > */ > + bool all_select_agg =3D true; Nit: use =E2=80=98is_=E2=80=99 or =E2=80=98if_=E2=80=99 prefix for = predicate variable. > sNC.ncFlags =3D NC_AllowAgg; > sNC.pSrcList =3D p->pSrc; > sNC.pNext =3D pOuterNC; > - > /* Resolve names in the result set. */ > - if (sqlite3ResolveExprListNames(sNC, p->pEList)) > - return WRC_Abort; Leave here explanation comment pls. Without any notion it is quite hard to understand that this snippet helps to check HAVING without GROUP BY queries. > + for (i =3D 0; i < p->pEList->nExpr; i++) { > + u16 has_agg_flag =3D sNC.ncFlags & NC_HasAgg; > + sNC.ncFlags &=3D ~NC_HasAgg; > + if (sqlite3ResolveExprNames(&sNC, = p->pEList->a[i].pExpr)) > + return WRC_Abort; > + all_select_agg &=3D (sNC.ncFlags & NC_HasAgg) !=3D= 0; > + sNC.ncFlags |=3D has_agg_flag; > + }