From: Vladimir Davydov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: imeevma@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v1 02/10] sql: rework SQL built-in functions hash table
Date: Mon, 16 Aug 2021 16:53:17 +0300 [thread overview]
Message-ID: <20210816135317.mxk7oi2xytgu5lnt@esperanza> (raw)
In-Reply-To: <7f889561e6e2fe205d91224eaf6c5c3e439a2a41.1628824421.git.imeevma@gmail.com>
On Fri, Aug 13, 2021 at 06:17:07AM +0300, imeevma@tarantool.org wrote:
> @@ -2615,23 +2099,30 @@ built_in_func_put(struct func *func)
> }
> }
>
> +static struct func *
> +find_built_in_func(struct Expr *expr, struct sql_func_dictionary *dict)
> +{
> + const char *name = expr->u.zToken;
> + int n = expr->x.pList != NULL ? expr->x.pList->nExpr : 0;
> + struct func *func = &dict->functions[0]->base;
> + assert(func->def->exports.sql);
> + int param_count = func->def->param_count;
> + if (param_count != -1 && param_count != n) {
> + diag_set(ClientError, ER_FUNC_WRONG_ARG_COUNT, name,
> + tt_sprintf("%d", func->def->param_count), n);
> + return NULL;
> + }
> + return func;
> +}
> +
> struct func *
> sql_func_find(struct Expr *expr)
> {
> const char *name = expr->u.zToken;
> - int n = expr->x.pList ? expr->x.pList->nExpr : 0;
> - struct func *func = built_in_func_get(name);
> - if (func != NULL) {
> - assert(func->def->exports.sql);
> - int param_count = func->def->param_count;
> - if (param_count != -1 && param_count != n) {
> - diag_set(ClientError, ER_FUNC_WRONG_ARG_COUNT, name,
> - tt_sprintf("%d", func->def->param_count), n);
> - return NULL;
> - }
> - return func;
> - }
> - func = func_by_name(name, strlen(name));
> + struct sql_func_dictionary *dict = built_in_func_get(name);
> + if (dict != NULL)
> + return find_built_in_func(expr, dict);
> + struct func *func = func_by_name(name, strlen(name));
> if (func == NULL) {
> diag_set(ClientError, ER_NO_SUCH_FUNCTION, name);
> return NULL;
Having a separate (from _func) two-level (name -> dictionary -> func)
hash for built-in functions looks ugly. Treating built-in functions and
user-defined functions differently here, but using the same struct func
for both kinds looks ugly as well. The old code, where both built-in
functions and user-defined functions lived in the same hash (and in
_func system space), looked consistent and neat.
If our goal is to enable static type checking of function arguments, we
can instead add a callback to struct func ('check'), which would raise
an error if supplied arguments are incorrect without invoking the
function. We wouldn't have a separate 'execute' callback for each
variant of the same function then, because all variants would share the
same struct func, like they do now, but do we really need it?
Another idea is to move built-in function name resolution completely to
the parser. Then we wouldn't need a hash for built-in functions at all
(nor would we need to have them in _func). I find this idea particularly
appealing, because after all built-in functions are like operators -
their names and argument types are known at the parse time - so
theoretically we could generate a separate opcode for them with all the
necessary information prepared by the paser. Please check out if this
is doable.
next prev parent reply other threads:[~2021-08-16 13:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-13 3:17 [Tarantool-patches] [PATCH v1 00/10] Check types of SQL built-in functions arguments Mergen Imeev via Tarantool-patches
2021-08-13 3:17 ` [Tarantool-patches] [PATCH v1 01/10] sql: modify signature of TRIM() Mergen Imeev via Tarantool-patches
2021-08-13 3:17 ` [Tarantool-patches] [PATCH v1 02/10] sql: rework SQL built-in functions hash table Mergen Imeev via Tarantool-patches
2021-08-16 13:53 ` Vladimir Davydov via Tarantool-patches [this message]
2021-08-13 3:17 ` [Tarantool-patches] [PATCH v1 03/10] sql: check number of arguments during parsing Mergen Imeev via Tarantool-patches
2021-08-13 3:17 ` [Tarantool-patches] [PATCH v1 04/10] sql: static type check for SQL built-in functions Mergen Imeev via Tarantool-patches
2021-08-13 3:17 ` [Tarantool-patches] [PATCH v1 05/10] sql: runtime " Mergen Imeev via Tarantool-patches
2021-08-13 3:17 ` [Tarantool-patches] [PATCH v1 06/10] sql: enable types checking for some functions Mergen Imeev via Tarantool-patches
2021-08-13 3:17 ` [Tarantool-patches] [PATCH v1 07/10] sql: fix result type of min() and max() functions Mergen Imeev via Tarantool-patches
2021-08-13 3:17 ` [Tarantool-patches] [PATCH v1 08/10] sql: check argument types of sum(), avg(), total() Mergen Imeev via Tarantool-patches
2021-08-13 3:17 ` [Tarantool-patches] [PATCH v1 09/10] sql: fix quote() function Mergen Imeev via Tarantool-patches
2021-08-13 3:17 ` [Tarantool-patches] [PATCH v1 10/10] sql: arguments check for string value functions Mergen Imeev via Tarantool-patches
2021-08-19 11:49 ` [Tarantool-patches] [PATCH v1 00/10] Check types of SQL built-in functions arguments Vladimir Davydov via Tarantool-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210816135317.mxk7oi2xytgu5lnt@esperanza \
--to=tarantool-patches@dev.tarantool.org \
--cc=imeevma@tarantool.org \
--cc=vdavydov@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH v1 02/10] sql: rework SQL built-in functions hash table' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox