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 4E5462E3F3 for ; Tue, 17 Apr 2018 14:45:11 -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 kS-8YDP1etyZ for ; Tue, 17 Apr 2018 14:45:11 -0400 (EDT) Received: from smtp15.mail.ru (smtp15.mail.ru [94.100.176.133]) (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 09FA12E3B0 for ; Tue, 17 Apr 2018 14:45:10 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v2 1/1] sql: remove ephemeral Expr from AddDefaultValue References: <0a797b62416743d6e6494949710b70a330f36c04.1523977261.git.kshcherbatov@tarantool.org> From: Vladislav Shpilevoy Message-ID: <3ba2877e-eb07-de72-4584-75171304d2e0@tarantool.org> Date: Tue, 17 Apr 2018 21:45:07 +0300 MIME-Version: 1.0 In-Reply-To: <0a797b62416743d6e6494949710b70a330f36c04.1523977261.git.kshcherbatov@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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, Kirill Shcherbatov Hello. Please, see my 4 comments below. On 17/04/2018 18:01, Kirill Shcherbatov wrote: > As we don't need Expr tree in DDL we could store only > string representation that's better to understand. > > Needed for #3051. > --- 1. Put here branch and issue links, as it pointed in guideline: https://tarantool.io/en/doc/1.9/dev_guide/developer_guidelines.html#how-to-submit-a-patch-for-review 2. Do not create separate branch for this - you can push this commit on the main branch, linked with the issue. > src/box/sql.c | 10 ++++------ > src/box/sql/build.c | 32 ++++++++++++++------------------ > 2 files changed, 18 insertions(+), 24 deletions(-) > > diff --git a/src/box/sql/build.c b/src/box/sql/build.c > index 394ee3a..4406955 100644 > --- a/src/box/sql/build.c > +++ b/src/box/sql/build.c > @@ -399,6 +399,8 @@ deleteTable(sqlite3 * db, Table * pTable) > if (pTable->def) { > /* fields has been allocated on separate region */ > struct field_def *fields = pTable->def->fields; > + for (uint32_t i = 0; i < pTable->def->field_count; ++i) > + sqlite3DbFree(sql_get(), fields[i].default_value); 3. I see, that fields deletion becomes more and more complex. Lets move this complexity into table building - into EndTable function. EndTable will move the def spread over different mallocs on a single big malloc by calling space_def_new again like this: old_def = pNewTable->def; pNewTable->def = space_def_new(). space_def_new here does this compaction for you. Then delete old_def in the same way as you do it in deleteTable now. It makes table->def be exactly the same as space->def, and in deleteTable you just call space_def_delete. > @@ -889,27 +891,21 @@ sqlite3AddDefaultValue(Parse * pParse, ExprSpan * pSpan) > "default value of column [%s] is not constant", > pCol->zName); > } else { > - /* A copy of pExpr is used instead of the original, as pExpr contains > - * tokens that point to volatile memory. The 'span' of the expression > - * is required by pragma table_info. > - */ > - Expr x; > assert(p->def); > struct field_def *field = > &p->def->fields[p->nCol - 1]; > - sql_expr_free(db, field->default_value_expr, false); > - > - memset(&x, 0, sizeof(x)); > - x.op = TK_SPAN; > - x.u.zToken = sqlite3DbStrNDup(db, (char *)pSpan->zStart, > - (int)(pSpan->zEnd - > - pSpan->zStart)); > - x.pLeft = pSpan->pExpr; > - x.flags = EP_Skip; > - > - field->default_value_expr = > - sqlite3ExprDup(db, &x, EXPRDUP_REDUCE); > - sqlite3DbFree(db, x.u.zToken); > + > + sqlite3DbFree(db, field->default_value); 4. How can it be not NULL here, if DEFAULT is not created yet? > + field->default_value = > + sqlite3DbStrNDup(db, (char *)pSpan->zStart, > + (int)(pSpan->zEnd - > + pSpan->zStart)); > + if (field->default_value == NULL) { > + assert(db->mallocFailed); > + pParse->rc = SQLITE_NOMEM_BKPT; > + pParse->nErr++; > + return; > + } > } > } > sql_expr_free(db, pSpan->pExpr, false); >