Tarantool development patches archive
 help / color / mirror / Atom feed
From: "n.pettik" <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Hollow111 <hollow653@gmail.com>
Subject: [tarantool-patches] Re: [PATCH] sql: xfer optimization issue
Date: Tue, 24 Apr 2018 02:40:42 +0300	[thread overview]
Message-ID: <93E4DAEA-EF90-479D-9F62-3D1CEB3CBE3F@tarantool.org> (raw)
In-Reply-To: <CAEi+_aos_j278_E-j9UsDcoqPm3Bd=E2oTQo_qBrFOOwx8sZUw@mail.gmail.com>

Hello. Consider comments below.

> diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
> index ae8dafb..87e1bad 100644
> --- a/src/box/sql/insert.c
> +++ b/src/box/sql/insert.c
> @@ -1645,6 +1645,9 @@ 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 == 2 && pSrc->idxType != 2)
> +	    || (pDest->idxType != 2 && pSrc->idxType == 2))

It is better to use SQLITE_IDXTYPE_PRIMARYKEY macros,
then hardcoded constants.

But the main thing: you forgot to add ‘return 0;’ statement here.

Codestyle nitpicking: put binary operator to previous line.
Also, put dots at the end of sentences.

>  	if (nDestCol != nSrcCol) {
>  		return 0;	/* Different number of columns */
>  	}
> @@ -1711,16 +1714,21 @@ xferOptimization(Parse * pParse,	/* Parser context */
>  	ExprList *pEList;	/* The result set of the SELECT */
>  	Table *pSrc;		/* The table in the FROM clause of SELECT */
>  	Index *pSrcIdx, *pDestIdx;	/* Source and destination indices */
> +	/* Source and destination indices */
> +	struct index *src_idx, *dest_idx;

You didn’t fixed remark from previous review:
>We don’t use forward var declaration: it is obsolete rule from ancient C standards.
Although it is not mandatory, but better fix it.

>  	struct SrcList_item *pItem;	/* An element of pSelect->pSrc */
>  	int i;			/* Loop counter */
>  	int iSrc, iDest;	/* Cursors from source and destination */
>  	int addr1;		/* Loop addresses */
>  	int emptyDestTest = 0;	/* Address of test for empty pDest */
>  	int emptySrcTest = 0;	/* Address of test for empty pSrc */
> +	/* Number of memory cell for cursors */
> +	int space_ptr_reg;

The same is here.

>  	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();
> +	/* Space pointer for pDest and pSrc */
> +	struct space *space;

And here.

> +	/* The xfer optimization is unable to test
> +	 * uniqueness while we have a unique
> +	 * PRIMARY KEY in any existing table.

Rephrase this sentence. Or I have missed smth:
uniqness is checked while tuple is inserted in space by
Tarantool facilities, isn’t it? For this reason, you can try to return
those if-checks for additional code-generation.
The only concern I have is about ‘on conflict replace'
error action: if source table isn’t initially empty, features 'on replace'
error action and you insert table which violates uniqueness - 
this replace action might fail.
I advise you to investigate such behaviour.

> +	 * This is the reason we can only run it
> +	 * if the destination table is initially empty.
> +	 * This block generates code to make
> +	 * that determination.
> +	 */
> +	addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0);
> +	VdbeCoverage(v);
> +	emptyDestTest = sqlite3VdbeAddOp0(v, OP_Goto);
> +	sqlite3VdbeJumpHere(v, addr1);
> +
> +	pDestIdx = sqlite3PrimaryKeyIndex(pDest);
> +	pSrcIdx = sqlite3PrimaryKeyIndex(pSrc);
> +	space = space_by_id(SQLITE_PAGENO_TO_SPACEID(pSrc->tnum));
> +	if((src_idx = space_index(space, 0 /* PK */)) == NULL)

Codestyle nitpicking: put space after ‘if’.
Also, do not ‘inline’ comments into code.
And why space can’t feature primary index?
AFAIK, only views don’t have PK, but src table is tested
to be real table:
	if (space_is_view(pSrc)) {
		return 0;	/* tab2 may not be a view */
	} 

> +		return 0;
> +	space_ptr_reg = ++pParse->nMem;
> +	sqlite3VdbeAddOp4Ptr(v, OP_LoadPtr, 0, space_ptr_reg, 0,
> +			     (void *) space);
> +	sqlite3VdbeAddOp3(v, OP_OpenWrite, iSrc,
> +			  pSrc->tnum, space_ptr_reg);
> +	VdbeComment((v, "%s", src_idx->def->name));
> +	space = space_by_id(SQLITE_PAGENO_TO_SPACEID(pDest->tnum));

Don’t be afraid of introducing new variables.
It would be better, if you use src_space and dest_space separately.

  reply	other threads:[~2018-04-23 23:40 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 [this message]
2018-04-27 15:45                 ` Hollow111
2018-05-03 22:57                   ` n.pettik
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=93E4DAEA-EF90-479D-9F62-3D1CEB3CBE3F@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