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 D1E7028A41 for ; Thu, 31 May 2018 11:01:23 -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 H59RdBbYo4hq for ; Thu, 31 May 2018 11:01:23 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (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 8D0DC28A27 for ; Thu, 31 May 2018 11:01:23 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v1 2/2] sql: use own region in Parser Date: Thu, 31 May 2018 18:01:18 +0300 Message-Id: <663c4c7deb9d8eff90407f50da2075990b44f815.1527778868.git.kshcherbatov@tarantool.org> In-Reply-To: References: In-Reply-To: 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: v.shpilevoy@tarantool.org, Kirill Shcherbatov Fixes #3438. --- src/box/sql/build.c | 6 +++--- src/box/sql/prepare.c | 6 ++---- src/box/sql/select.c | 2 +- src/box/sql/sqliteInt.h | 4 ++-- src/box/sql/tokenize.c | 10 ++++++---- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/box/sql/build.c b/src/box/sql/build.c index e376295..4e77084 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -636,7 +636,7 @@ sql_field_retrieve(Parse *parser, Table *table, uint32_t id) if (id >= table->def->exact_field_count) { uint32_t columns_new = table->def->exact_field_count; columns_new = (columns_new > 0) ? 2 * columns_new : 1; - struct region *region = &fiber()->gc; + struct region *region = &parser->region; field = region_alloc(region, columns_new * sizeof(table->def->fields[0])); if (field == NULL) { @@ -698,7 +698,7 @@ sqlite3AddColumn(Parse * pParse, Token * pName, Token * pType) if (sql_field_retrieve(pParse, p, (uint32_t) p->def->field_count) == NULL) return; - struct region *region = &fiber()->gc; + struct region *region = &pParse->region; z = region_alloc(region, pName->n + 1); if (z == NULL) { diag_set(OutOfMemory, pName->n + 1, @@ -906,7 +906,7 @@ sqlite3AddDefaultValue(Parse * pParse, ExprSpan * pSpan) assert(p->def != NULL); struct field_def *field = &p->def->fields[p->def->field_count - 1]; - struct region *region = &fiber()->gc; + struct region *region = &pParse->region; uint32_t default_length = (int)(pSpan->zEnd - pSpan->zStart); field->default_value = region_alloc(region, default_length + 1); diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c index 8d94642..e796077 100644 --- a/src/box/sql/prepare.c +++ b/src/box/sql/prepare.c @@ -437,8 +437,7 @@ sql_parser_create(struct Parse *parser, sqlite3 *db) { memset(parser, 0, sizeof(struct Parse)); parser->db = db; - struct region *region = &fiber()->gc; - parser->region_initial_size = region_used(region); + region_create(&parser->region, &cord()->slabc); } void @@ -454,6 +453,5 @@ sql_parser_destroy(Parse *parser) db->lookaside.bDisable -= parser->disableLookaside; } parser->disableLookaside = 0; - struct region *region = &fiber()->gc; - region_truncate(region, parser->region_initial_size); + region_destroy(&parser->region); } diff --git a/src/box/sql/select.c b/src/box/sql/select.c index 5fbcbaf..b26565b 100644 --- a/src/box/sql/select.c +++ b/src/box/sql/select.c @@ -1762,7 +1762,7 @@ sqlite3ColumnsFromExprList(Parse * parse, ExprList * expr_list, Table *table) * names for existing table. */ assert(table->def->fields == NULL); - struct region *region = &fiber()->gc; + struct region *region = &parse->region; table->def->fields = region_alloc(region, nCol * sizeof(table->def->fields[0])); if (table->def->fields == NULL) { diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h index abf1543..4275f72 100644 --- a/src/box/sql/sqliteInt.h +++ b/src/box/sql/sqliteInt.h @@ -2913,8 +2913,8 @@ struct Parse { u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */ u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */ u8 disableTriggers; /* True to disable triggers */ - /** Region size at the Parser launch. */ - size_t region_initial_size; + /* Region to make SQL temp allocations. */ + struct region region; /************************************************************************** * Fields above must be initialized to zero. The fields that follow, diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c index fc4fe25..1fd8b29 100644 --- a/src/box/sql/tokenize.c +++ b/src/box/sql/tokenize.c @@ -544,16 +544,18 @@ sql_expr_compile(sqlite3 *db, const char *expr, struct Expr **result) { const char *outer = "SELECT "; int len = strlen(outer) + strlen(expr); - char *stmt = (char *) region_alloc(&fiber()->gc, len + 1); + + struct Parse parser; + sql_parser_create(&parser, db); + parser.parse_only = true; + + char *stmt = (char *)region_alloc(&parser.region, len + 1); if (stmt == NULL) { diag_set(OutOfMemory, len + 1, "region_alloc", "stmt"); return -1; } sprintf(stmt, "%s%s", outer, expr); - struct Parse parser; - sql_parser_create(&parser, db); - parser.parse_only = true; char *unused; if (sqlite3RunParser(&parser, stmt, &unused) != SQLITE_OK) { diag_set(ClientError, ER_SQL_EXECUTE, expr); -- 2.7.4