[tarantool-patches] [PATCH v2 4/8] sql: get rid of SQL_FUNC_COUNT flag
Kirill Shcherbatov
kshcherbatov at tarantool.org
Thu Aug 8 17:50:48 MSK 2019
Tarantool's SQL engine generates a different VDBE bytecode
for ..COUNT(*).. and ..COUNT(fieldname).. operations:
the first one produces a lightweight OP_Count operation that uses
native mechanism to report the count of record in index while
the second one pessimistically opens a space read iterator and
uses Count aggregate function.
A helper routine is_simple_count decides whether such
optimisation is correct. Using SQL_FUNC_COUNT flag to mark a
dummy (non-functional) function entry with 0 arguments is a bad
practice and should be reworked in relation with introducing
a uniform functions cache in further patches.
Therefore SQL_FUNC_COUNT flag test in is_simple_count helper
was replaced with more straightforward test with manually looking
for count of function arguments passed.
Needed for #2200, #4113, #2233
---
src/box/sql/sqlInt.h | 1 -
src/box/sql/func.c | 4 ++--
src/box/sql/select.c | 3 ++-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 4adb30c5c..941c87420 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -1312,7 +1312,6 @@ struct FuncDestructor {
*/
#define SQL_FUNC_LENGTH 0x0040 /* Built-in length() function */
#define SQL_FUNC_TYPEOF 0x0080 /* Built-in typeof() function */
-#define SQL_FUNC_COUNT 0x0100 /* Built-in count(*) aggregate */
#define SQL_FUNC_COALESCE 0x0200 /* Built-in coalesce() or ifnull() */
#define SQL_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */
#define SQL_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index f9c0a819e..e011fd958 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -1910,8 +1910,8 @@ sqlRegisterBuiltinFunctions(void)
FIELD_TYPE_NUMBER),
AGGREGATE(avg, 1, 0, 0, sum_step, avgFinalize,
FIELD_TYPE_NUMBER),
- AGGREGATE2(count, 0, 0, 0, countStep, countFinalize,
- SQL_FUNC_COUNT, FIELD_TYPE_INTEGER),
+ AGGREGATE(count, 0, 0, 0, countStep, countFinalize,
+ FIELD_TYPE_INTEGER),
AGGREGATE(count, 1, 0, 0, countStep, countFinalize,
FIELD_TYPE_INTEGER),
AGGREGATE(group_concat, 1, 0, 0, groupConcatStep,
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index c31076694..921a52150 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -4381,7 +4381,8 @@ is_simple_count(struct Select *select, struct AggInfo *agg_info)
return NULL;
if (NEVER(agg_info->nFunc == 0))
return NULL;
- if ((agg_info->aFunc[0].pFunc->funcFlags & SQL_FUNC_COUNT) == 0)
+ if (agg_info->aFunc->pExpr->x.pList != NULL &&
+ agg_info->aFunc->pExpr->x.pList->nExpr > 0)
return NULL;
if (expr->flags & EP_Distinct)
return NULL;
--
2.22.0
More information about the Tarantool-patches
mailing list