From: "n.pettik" <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: "N. Tatunov" <hollow653@gmail.com>
Subject: [tarantool-patches] Re: [PATCH] sql: xfer optimization issue
Date: Fri, 4 May 2018 01:57:11 +0300 [thread overview]
Message-ID: <F68261EE-EDE3-48FA-9864-7BA2653798B0@tarantool.org> (raw)
In-Reply-To: <CAEi+_aqxW-RPhC5tFBPQSmPewR48SSnDMiB2_iw6Etzpqrni4Q@mail.gmail.com>
> diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
> index ae8dafb..734ff34 100644
> --- a/src/box/sql/insert.c
> +++ b/src/box/sql/insert.c
> @@ -1645,6 +1645,12 @@ xferCompatibleIndex(Index * pDest, Index * pSrc)
> assert(pDest->pTable != pSrc->pTable);
> uint32_t nDestCol = index_column_count(pDest);
> uint32_t nSrcCol = index_column_count(pSrc);
> + /* One of them is PK while the other isn't. */
> + if ((pDest->idxType == SQLITE_IDXTYPE_PRIMARYKEY &&
> + pSrc->idxType != SQLITE_IDXTYPE_PRIMARYKEY) ||
> + (pDest->idxType != SQLITE_IDXTYPE_PRIMARYKEY &&
> + pSrc->idxType == SQLITE_IDXTYPE_PRIMARYKEY))
> + return 0;
Why don’t just compare their types? Wouldn’t it be easier?
Yep, such condition would be little bit stronger, but I think it is worth it.
> @@ -1718,9 +1724,10 @@ xferOptimization(Parse * pParse, /* Parser context */
> int emptyDestTest = 0; /* Address of test for empty pDest */
> int emptySrcTest = 0; /* Address of test for empty pSrc */
> Vdbe *v; /* The VDBE we are building */
> - int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */
> int regData, regTupleid; /* Registers holding data and tupleid */
> struct session *user_session = current_session();
> + int dest_has_replace_action = 0;
> + int confl_action_default = 0;
Call it error action. Also, it is better to use bool type
(even if bool might be really int underhood). And bool values usually
comes with ‘is_’ or ‘has_' prefix.
> @@ -1737,8 +1744,10 @@ xferOptimization(Parse * pParse, /* Parser context */
> if (onError == ON_CONFLICT_ACTION_DEFAULT) {
> if (pDest->iPKey >= 0)
> onError = pDest->keyConf;
> - if (onError == ON_CONFLICT_ACTION_DEFAULT)
> + if (onError == ON_CONFLICT_ACTION_DEFAULT) {
> onError = ON_CONFLICT_ACTION_ABORT;
> + confl_action_default = 1;
Why do you need this variable at all? I mean, DEFAULT always
is an alias to ABORT, isn’t it?
> + }
> }
> assert(pSelect->pSrc); /* allocated even if there is no FROM clause */
> if (pSelect->pSrc->nSrc != 1) {
> @@ -1828,15 +1837,16 @@ xferOptimization(Parse * pParse, /* Parser context */
> return 0; /* Default values must be the same for all columns */
> }
> }
> + if (pDestCol->notNull == ON_CONFLICT_ACTION_REPLACE)
> + dest_has_replace_action = 1;
Don’t confuse NOT NULL error action for field and conflict action for index:
Index->onError is not the same as Column->notNull.
> for (pDestIdx = pDest->pIndex; pDestIdx; pDestIdx = pDestIdx->pNext) {
> - if (index_is_unique(pDestIdx)) {
> - destHasUniqueIdx = 1;
> - }
> for (pSrcIdx = pSrc->pIndex; pSrcIdx; pSrcIdx = pSrcIdx->pNext) {
> if (xferCompatibleIndex(pDestIdx, pSrcIdx))
> break;
> }
> + if (pDestIdx->onError != ON_CONFLICT_ACTION_REPLACE)
> + dest_has_replace_action = 1;
Wait, you assign ’true’ to variable ‘has_replace’ when it is not really replace…
It looks very strange.
> @@ -1875,58 +1885,63 @@ xferOptimization(Parse * pParse, /* Parser context */
> +
> + /* Xfer optimization is unable to correctly insert
> + * data in case there's a conflict action
> + * other than ON_CONFLICT_ACTION_ROLLBACK or there's
> + * ON_CONFLICT_ACTION_DEFAULT which was transformed into
> + * ON_CONFLICT_ACTION_ABORT for insertion while we have a
> + * ON_CONFLICT_ACTION_REPLACE for any of constraints.
I would use only names of actions, these enum names are too long.
But it is up to you.
> + if (onError != ON_CONFLICT_ACTION_ROLLBACK ||
> + (confl_action_default == 1 &&
> + dest_has_replace_action == 1)) {
You can fit two lines above into one...
> + int space_ptr_reg = ++pParse->nMem;
> + struct space *src_space =
> + space_by_id(SQLITE_PAGENO_TO_SPACEID(pSrc->tnum));
> + struct space *dest_space =
> + space_by_id(SQLITE_PAGENO_TO_SPACEID(pDest->tnum));
> + struct index *src_idx = space_index(src_space, 0);
> + struct index *dest_idx;
Why don’t make index lookup for destination space right here?
> + pDestIdx = sqlite3PrimaryKeyIndex(pDest);
> + pSrcIdx = sqlite3PrimaryKeyIndex(pSrc);
These variables are unused.
> diff --git a/test/sql-tap/gh-3307-xfer-optimization-issue.test.lua b/test/sql-tap/gh-3307-xfer-optimization-issue.test.lua
> new file mode 100755
> index 0000000..860b4c3
> --- /dev/null
> +++ b/test/sql-tap/gh-3307-xfer-optimization-issue.test.lua
> @@ -0,0 +1,233 @@
> +#!/usr/bin/env tarantool
> +test = require("sqltester")
> +test:plan(18)
The only one thing I don’t really like in these tests is the absence
of verification of occurred optimisation. Could you come up with the way
how to check it?
next prev parent reply other threads:[~2018-05-03 22:57 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-18 15:32 [tarantool-patches] " N.Tatunov
2018-04-18 16:33 ` [tarantool-patches] " Hollow111
2018-04-19 11:22 ` n.pettik
2018-04-19 15:36 ` Hollow111
2018-04-20 1:02 ` n.pettik
2018-04-20 15:09 ` Hollow111
2018-04-20 16:09 ` n.pettik
2018-04-20 17:59 ` Hollow111
2018-04-23 23:40 ` n.pettik
2018-04-27 15:45 ` Hollow111
2018-05-03 22:57 ` n.pettik [this message]
2018-05-04 12:54 ` Hollow111
2018-06-28 10:18 ` Alexander Turenko
2018-07-09 15:50 ` Alexander Turenko
2018-07-16 12:54 ` Nikita Tatunov
2018-07-16 13:06 ` n.pettik
2018-07-16 13:20 ` Nikita Tatunov
2018-07-16 18:37 ` Nikita Tatunov
2018-07-16 19:12 ` n.pettik
2018-07-16 21:27 ` Nikita Tatunov
2018-07-18 15:13 ` n.pettik
2018-07-18 20:18 ` Nikita Tatunov
2018-07-19 0:20 ` n.pettik
2018-07-19 17:26 ` Nikita Tatunov
2018-07-20 3:20 ` n.pettik
2018-07-20 11:56 ` Nikita Tatunov
2018-07-20 16:43 ` n.pettik
2018-07-20 16:58 ` Nikita Tatunov
2018-07-29 1:12 ` Alexander Turenko
2018-07-29 11:23 ` n.pettik
2018-07-29 15:16 ` Alexander Turenko
2018-07-30 18:33 ` Nikita Tatunov
2018-07-30 22:17 ` Alexander Turenko
2018-07-31 11:48 ` Nikita Tatunov
2018-07-31 13:29 ` Alexander Turenko
2018-07-31 17:04 ` Nikita Tatunov
2018-07-31 17:44 ` Alexander Turenko
2018-08-21 16:43 ` Kirill Yukhin
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=F68261EE-EDE3-48FA-9864-7BA2653798B0@tarantool.org \
--to=korablev@tarantool.org \
--cc=hollow653@gmail.com \
--cc=tarantool-patches@freelists.org \
--subject='[tarantool-patches] Re: [PATCH] sql: xfer optimization issue' \
/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