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 0D46E2781D for ; Fri, 20 Jul 2018 10:07:12 -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 3nZar4dBc0zQ for ; Fri, 20 Jul 2018 10:07:11 -0400 (EDT) Received: from smtp39.i.mail.ru (smtp39.i.mail.ru [94.100.177.99]) (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 AF935275E9 for ; Fri, 20 Jul 2018 10:07:11 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [tarantool-patches] Re: [PATCH] sql: get rid off tnum field of struct Table From: "n.pettik" In-Reply-To: Date: Fri, 20 Jul 2018 17:07:03 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: 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: Kirill Yukhin > diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c > index 3af9f9a..504701d 100644 > --- a/src/box/sql/insert.c > +++ b/src/box/sql/insert.c > @@ -384,7 +384,7 @@ sqlite3Insert(Parse * pParse, /* Parser = context */ > if (pTab =3D=3D NULL) > goto insert_cleanup; >=20 > - space_id =3D SQLITE_PAGENO_TO_SPACEID(pTab->tnum); > + space_id =3D pTab->def->id; >=20 > /* Figure out if we have any triggers and if the table being > * inserted into is a view > @@ -742,7 +742,7 @@ sqlite3Insert(Parse * pParse, /* Parser = context */ > if (i =3D=3D pTab->iAutoIncPKey) { > sqlite3VdbeAddOp2(v, > = OP_NextAutoincValue, > - pTab->tnum, > + = SQLITE_PAGENO_FROM_SPACEID_AND_INDEXID(pTab->def->id, 0), It looks disgusting.. Lets also refactor OP_NextAutoincValue so that it accepts raw space_id. After that, remove these SQLITE_PAGENO macroses at all. > diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c > index cabe22b..0c838fa 100644 > --- a/src/box/sql/pragma.c > +++ b/src/box/sql/pragma.c > @@ -432,9 +432,8 @@ sqlite3Pragma(Parse * pParse, Token * pId, = /* First part of [schema.]id field */ > for (i =3D = sqliteHashFirst(&db->pSchema->tblHash); i; > i =3D sqliteHashNext(i)) { > Table *pTab =3D sqliteHashData(i); > - uint32_t space_id =3D > - = SQLITE_PAGENO_TO_SPACEID(pTab->tnum); > - struct space *space =3D = space_by_id(space_id); > + struct space *space; > + space =3D space_by_id(pTab->def->id); Squash two lines into one: struct space *space =3D space_by_id(pTab->def->id); > @@ -161,18 +142,18 @@ extern int > sqlite3InitDatabase(sqlite3 * db) > { > int rc; > - InitData initData; > + struct init_data init; >=20 > assert(db->pSchema !=3D NULL); >=20 > - memset(&initData, 0, sizeof(InitData)); > - initData.db =3D db; > + memset(&init, 0, sizeof(init)); > + init.db =3D db; >=20 > /* Load schema from Tarantool - into the primary db only. */ > - tarantoolSqlite3LoadSchema(&initData); > + tarantoolSqlite3LoadSchema(&init); >=20 > - if (initData.rc) { > - rc =3D initData.rc; > + if (init.rc) { > + rc =3D init.rc; > goto error_out; > } >=20 > -/* > +/** > * A pointer to this structure is used to communicate information > - * from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback. > - */ > -typedef struct { > - sqlite3 *db; /* The database being initialized */ > - char **pzErrMsg; /* Error message stored here */ > - int rc; /* Result code stored here */ > -} InitData; > + * from sqlite3Init and OP_ParseSchema into the sql_init_callback. > + */ > +struct init_data { > + /* The database being initialized */ > + sqlite3 *db; > + /* Error message stored here */ > + char **pzErrMsg; > + /* Result code stored here */ Comments inside struct definition should look like: /** =E2=80=A6 */ And put dot at the end of sentences. >=20 > diff --git a/src/box/sql/tarantoolInt.h b/src/box/sql/tarantoolInt.h > index f043a60..b34e671 100644 > --- a/src/box/sql/tarantoolInt.h > +++ b/src/box/sql/tarantoolInt.h > @@ -44,7 +44,7 @@ > ((pgno) & 1023) >=20 > /* Load database schema from Tarantool. */ > -void tarantoolSqlite3LoadSchema(InitData * init); > +void tarantoolSqlite3LoadSchema(struct init_data * init); struct init_data *init =E2=80=94 remove extra space. > @@ -2178,8 +2171,8 @@ whereLoopInsert(WhereLoopBuilder * pBuilder, = WhereLoop * pTemplate) > } > rc =3D whereLoopXfer(db, p, pTemplate); > Index *pIndex =3D p->pIndex; > - if (pIndex && pIndex->tnum =3D=3D 0) > - p->pIndex =3D 0; > + if (pIndex !=3D NULL && pIndex->pTable->def->opts.is_view) > + p->pIndex =3D NULL; > return rc; > } These conditions don=E2=80=99t seem to be equivalent: view features = ordinary space_id AFAIK. >=20 > @@ -2347,8 +2340,8 @@ whereRangeVectorLen(Parse * pParse, /* = Parsing context */ > * terms only. If it is modified, this value is restored before this > * function returns. > * > - * If pProbe->tnum=3D=3D0, that means pIndex is a fake index used for = the > - * INTEGER PRIMARY KEY. > + * If pProbe->def->space_id=3D=3D0, that means pIndex is a fake index > + * used for the INTEGER PRIMARY KEY. But in fact you use another sign of fake index: iid =3D=3D UINT32_MAX > */ > static int > whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder, /* The WhereLoop = factory */ > @@ -2391,12 +2384,11 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * = pBuilder, /* The WhereLoop factory */ > opMask =3D > WO_EQ | WO_IN | WO_GT | WO_GE | WO_LT | WO_LE | = WO_ISNULL; > } > - struct space *space =3D > - space_by_id(SQLITE_PAGENO_TO_SPACEID(pProbe->tnum)); > + struct space *space =3D space_by_id(pProbe->def->space_id); > struct index *idx =3D NULL; > struct index_stat *stat =3D NULL; > - if (space !=3D NULL) { > - idx =3D space_index(space, = SQLITE_PAGENO_TO_INDEXID(pProbe->tnum)); > + if (space !=3D NULL && pProbe->def->iid !=3D UINT32_MAX) { > + idx =3D space_index(space, pProbe->def->iid); > assert(idx !=3D NULL); > stat =3D idx->def->opts.stat; > } >=20 > @@ -2577,7 +2569,7 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * = pBuilder, /* The WhereLoop factory */ > assert(eOp & (WO_ISNULL | WO_EQ | WO_IN)); >=20 > assert(pNew->nOut =3D=3D saved_nOut); > - if (pTerm->truthProb <=3D 0 && pProbe->tnum !=3D = 0 ) { > + if (pTerm->truthProb <=3D 0 && = !pProbe->pTable->def->opts.is_view) { The same as previous remark: these conditions don=E2=80=99t seem to be = equivalent