[tarantool-patches] Re: [PATCH 2/2] sql: make aggregate functions types more strict
Konstantin Osipov
kostja at tarantool.org
Fri Apr 5 22:48:15 MSK 2019
* Ivan Koptelov <ivan.koptelov at tarantool.org> [19/04/05 18:02]:
> +/*
> + * This structure is for keeping context during work of
> + * aggregate function.
> + */
> +struct aggregate_context {
> + /** Value being aggregated. (e.g. current MAX or current counter value). */
> + Mem value;
> + /** Reference value to keep track of previous argument's type. */
> + Mem reference_value;
> +};
Why not call this struct agg_value?
Besides, keeping a reference to the previous argument is an
overkill. Why not keep a type instead, and assign it to
FIELD_TYPE_SCALAR initially and change to a more specific type
after the first assignment?
> + } else {
> + diag_set(ClientError, ER_INCONSISTENT_TYPES,
> + "INTEGER or FLOAT", mem_type_to_str(argv[0]));
> + context->fErrorOrAux = 1;
> + context->isError = SQL_TARANTOOL_ERROR;
This message would look confusing. Could we get rid of "or" in the
message and be more specific about what is inconsistent?
> + if (sql_type != ref_sql_type) {
> + is_compatible = false;
> + if ((sql_type == SQL_INTEGER || sql_type == SQL_FLOAT) &&
> + (ref_sql_type == SQL_INTEGER ||
> + ref_sql_type == SQL_FLOAT)) {
> + is_compatible = true;
This is a very hot path and doing so much work to check
compatibility is a) clumsy when reading b) slow c) hard to
maintain.
Please use a compatibility matrix statically defined as a 8x8
bitmap.
Besides, I guess you can get rid of this check for most common
cases - averaging a column of the same type - so this is perhaps
better to make a separate opcode, not part of the main opcode, and
emit only when we're not sure the type is going to be the same
across all values. I don't know how hard this is to do, however -
perhaps should be moved into a separate patch, but I'd guess
detecting that the aggregate function argument has a non-mutable
type is not hard.
--
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
http://tarantool.io - www.twitter.com/kostja_osipov
More information about the Tarantool-patches
mailing list