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 EB3F427DAD for ; Fri, 20 Jul 2018 10:34:36 -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 6fdtgYYwh4aa for ; Fri, 20 Jul 2018 10:34:36 -0400 (EDT) Received: from smtp20.mail.ru (smtp20.mail.ru [94.100.179.251]) (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 5095E27DAC for ; Fri, 20 Jul 2018 10:34:36 -0400 (EDT) From: "n.pettik" Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_3EC59EBE-C12C-47D8-84DA-4383995B8A75" Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [tarantool-patches] Re: [PATCH] sql: refactor primary index creation Date: Fri, 20 Jul 2018 17:34:26 +0300 In-Reply-To: <20180720130806.mjf7ww3qt4t7maot@tarantool.org> References: <20180720130806.mjf7ww3qt4t7maot@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: Kirill Yukhin --Apple-Mail=_3EC59EBE-C12C-47D8-84DA-4383995B8A75 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii LGTM, except for 1 comment. > @@ -862,10 +861,6 @@ sqlite3AddDefaultValue(Parse * pParse, ExprSpan * = pSpan) > * a primary key (and this is the second primary key) then create an > * error. > * > - * Set the Table.iPKey field of the table under construction to be = the > - * index of the INTEGER PRIMARY KEY column. > - * Table.iPKey is set to -1 if there is no INTEGER PRIMARY KEY. > - * > * If the key is not an INTEGER PRIMARY KEY, then create a unique > * index for the key. No index is created for INTEGER PRIMARY KEYs. > */ > @@ -923,14 +918,24 @@ sqlite3AddPrimaryKey(Parse * pParse, /* = Parsing context */ > (pTab->def->fields[iCol].type =3D=3D FIELD_TYPE_INTEGER) && > sortOrder !=3D SORT_ORDER_DESC) { > assert(autoInc =3D=3D 0 || autoInc =3D=3D 1); > - pTab->iPKey =3D iCol; > - pTab->keyConf =3D (u8) onError; > if (autoInc) { > pTab->iAutoIncPKey =3D iCol; > pTab->tabFlags |=3D TF_Autoincrement; > } > - if (pList) > - pParse->iPkSortOrder =3D pList->a[0].sort_order; > + struct sqlite3 *db =3D pParse->db; > + struct ExprList *list; > + struct Token token; > + sqlite3TokenInit(&token, pTab->def->fields[iCol].name); > + list =3D sql_expr_list_append(db, NULL, > + sqlite3ExprAlloc(db, TK_ID, > + &token, = 0)); > + if (list =3D=3D NULL) > + return; I guess here should also be goto primary_key_exit; --Apple-Mail=_3EC59EBE-C12C-47D8-84DA-4383995B8A75 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
LGTM, except for 1 comment.

@@ -862,10 +861,6 @@ = sqlite3AddDefaultValue(Parse * pParse, ExprSpan * pSpan)
 * a primary key (and this is the second = primary key) then create an
 * error.
 *
- * Set the Table.iPKey field of = the table under construction to be the
- * index of the INTEGER PRIMARY = KEY column.
- * Table.iPKey is set to -1 if there is = no INTEGER PRIMARY KEY.
- *
 * If the key is not an INTEGER PRIMARY = KEY, then create a unique
 * index for the key. =  No index is created for INTEGER PRIMARY KEYs.
 */
@@ -923,14 +918,24 @@ = sqlite3AddPrimaryKey(Parse * pParse, = /* Parsing context */
    (pTab->d= ef->fields[iCol].type =3D=3D FIELD_TYPE_INTEGER) &&
    sortOrder = !=3D SORT_ORDER_DESC) {
assert(autoInc =3D=3D 0 || autoInc =3D=3D = 1);
- = pTab->iPKey =3D iCol;
- = pTab->keyConf =3D (u8) = onError;
= if (autoInc) {
pTab->iAutoIncPKey =3D iCol;
pTab->tabFlags |=3D = TF_Autoincrement;
= }
- if (pList)
- pParse->iPkSortOrder =3D = pList->a[0].sort_order;
+ struct sqlite3 *db =3D = pParse->db;
+ = struct ExprList *list;
+ = struct Token token;
+ = sqlite3TokenInit(&token, = pTab->def->fields[iCol].name);
+ list =3D sql_expr_list_append(db, = NULL,
+ =     sqlite3Expr= Alloc(db, TK_ID,
+ =      &= token, 0));
+ = if (list =3D=3D NULL)
+ = return;

I guess = here should also be goto primary_key_exit;

= --Apple-Mail=_3EC59EBE-C12C-47D8-84DA-4383995B8A75--