From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 06F8B2A6C2 for ; Thu, 22 Mar 2018 07:04:06 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9ky2HDo903jQ for ; Thu, 22 Mar 2018 07:04:05 -0400 (EDT) Received: from smtp55.i.mail.ru (smtp55.i.mail.ru [217.69.128.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id BA0F125D1E for ; Thu, 22 Mar 2018 07:04:05 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: [tarantool-patches] Re: [PATCH 1/4] sql: pass space pointer to OP_OpenRead/OpenWrite From: "v.shpilevoy@tarantool.org" In-Reply-To: <7F0DB390-F7BA-4E1F-AB93-9DB8498BCFD5@tarantool.org> Date: Thu, 22 Mar 2018 14:04:00 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: <46d0750257b6b5a256210b063515b1b05f4d7d37.1521583434.git.korablev@tarantool.org> <20180321131450.otxkluudlhf3yh2i@tarantool.org> <7F0DB390-F7BA-4E1F-AB93-9DB8498BCFD5@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: =?utf-8?B?0JrQuNGA0LjQu9C7INCu0YXQuNC9?= , Nikita Pettik See below 1 comment, and 1 off topic comment. And look at travis - it fails on the branch. >=20 > Originally in SQLite, to open table (i.e. btree) it was required to = pass > number of page root to OP_OpenRead or OP_OpenWrite opcodes as an > argument. However, now there are only Tarantool spaces and nothing > prevents from operating directly on pointers to them. Thus, to pass > pointers from compile time to runtime, opcode OP_LoadPtr has been > introduced. It fetches pointer from P4 and stores to the register > specified by P2. > It is worth mentioning that, pointers are able to expire after schema > changes (i.e. after DML routine). For this reason, schema version is > saved to VDBE at compile time and checked each time during cursor > opening. >=20 > Part of #3252 > --- > src/box/sql/analyze.c | 17 +++++- > src/box/sql/build.c | 7 ++- > src/box/sql/expr.c | 14 ++++- > src/box/sql/fkey.c | 11 +++- > src/box/sql/insert.c | 36 ++++++++++-- > src/box/sql/opcodes.c | 137 = +++++++++++++++++++++---------------------- > src/box/sql/opcodes.h | 157 = +++++++++++++++++++++++++------------------------- > src/box/sql/select.c | 11 +++- > src/box/sql/vdbe.c | 13 +++++ > src/box/sql/vdbe.h | 2 + > src/box/sql/vdbeInt.h | 3 + > src/box/sql/vdbeaux.c | 11 ++++ > src/box/sql/where.c | 12 +++- > 13 files changed, 272 insertions(+), 159 deletions(-) >=20 > diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c > index db06d0182..d121dd2b9 100644 > --- a/src/box/sql/analyze.c > +++ b/src/box/sql/analyze.c > @@ -174,10 +174,16 @@ openStatTable(Parse * pParse, /* Parsing = context */ > =20 > /* Open the sql_stat[134] tables for writing. */ > for (i =3D 0; aTable[i]; i++) { > + struct space *space =3D > + space_by_id(SQLITE_PAGENO_TO_SPACEID(aRoot[i])); > + assert(space !=3D NULL); > + int space_ptr_reg =3D ++pParse->nMem; > + sqlite3VdbeAddOp4Ptr(v, OP_LoadPtr, 0, space_ptr_reg, 0, > + (void *) space); > int addr; > addr =3D > sqlite3VdbeAddOp3(v, OP_OpenWrite, iStatCur + i, = aRoot[i], > - 0); > + space_ptr_reg); 1. Why do you pass here p3, if it is not used in OP_OpenWrite? Why can = not you just use sqlite3VdbeAddOp2 here? Same about OpenRead in all the = diff below. And how about to wrap this pair of calls = sqlite3VdbeAddOp4Ptr(space) + sqlite3VdbeAddOp3(open_read/write) into a = separate function? This code is repeated many times, as I can see. > v->aOp[addr].p4.pKeyInfo =3D 0; > v->aOp[addr].p4type =3D P4_KEYINFO; > sqlite3VdbeChangeP5(v, aCreateTbl[i]); > @@ -814,6 +820,7 @@ analyzeOneTable(Parse * pParse, /* Parser = context */ > int iTabCur; /* Table cursor */ > Vdbe *v; /* The virtual machine being built up */ > int i; /* Loop counter */ > + int space_ptr_reg =3D iMem++; Off topic: How about create a mempool of Mems? I see, that this object = is created really often and in big amount (see = src/lib/small/small/mempool.h). (It is not a part of the patch - just = think about it, and possibly open a ticket, if it worth). >=20 >=20 >=20