Tarantool development patches archive
 help / color / mirror / Atom feed
From: Konstantin Osipov <kostja@tarantool.org>
To: tarantool-patches@freelists.org
Cc: korablev@tarantool.org, Ivan Koptelov <ivan.koptelov@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH 2/2] sql: make aggregate functions types more strict
Date: Fri, 5 Apr 2019 22:48:15 +0300	[thread overview]
Message-ID: <20190405194815.GH3789@chai> (raw)
In-Reply-To: <49e4ae0bc187dc02f908427692c0ddb2cc2d36a8.1554475881.git.ivan.koptelov@tarantool.org>

* Ivan Koptelov <ivan.koptelov@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

  reply	other threads:[~2019-04-05 19:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-05 14:57 [tarantool-patches] [PATCH 0/2] " Ivan Koptelov
2019-04-05 14:57 ` [tarantool-patches] [PATCH 1/2] " Ivan Koptelov
2019-04-09 14:52   ` [tarantool-patches] " n.pettik
2019-04-05 14:57 ` [tarantool-patches] [PATCH 2/2] " Ivan Koptelov
2019-04-05 19:48   ` Konstantin Osipov [this message]
2019-04-17 12:50     ` [tarantool-patches] " i.koptelov
2019-04-17 13:19       ` n.pettik
2019-04-09 14:52   ` n.pettik
2019-04-23 15:38     ` i.koptelov
2019-04-24 17:37       ` n.pettik
2019-05-06 13:24         ` i.koptelov

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=20190405194815.GH3789@chai \
    --to=kostja@tarantool.org \
    --cc=ivan.koptelov@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH 2/2] sql: make aggregate functions types more strict' \
    /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