Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org
Cc: v.shpilevoy@tarantool.org,
	Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [tarantool-patches] [PATCH v1 2/2] sql: use own region in Parser
Date: Thu, 31 May 2018 18:01:18 +0300	[thread overview]
Message-ID: <663c4c7deb9d8eff90407f50da2075990b44f815.1527778868.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1527778868.git.kshcherbatov@tarantool.org>
In-Reply-To: <cover.1527778868.git.kshcherbatov@tarantool.org>

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

  parent reply	other threads:[~2018-05-31 15:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-31 15:01 [tarantool-patches] [PATCH v1 0/2] sql: Create special region for parser Kirill Shcherbatov
2018-05-31 15:01 ` [tarantool-patches] [PATCH v1 1/2] sql: remove parser construct, destruct to sql.h Kirill Shcherbatov
2018-05-31 15:41   ` [tarantool-patches] " Vladislav Shpilevoy
2018-05-31 15:49     ` Kirill Shcherbatov
2018-05-31 15:01 ` Kirill Shcherbatov [this message]
2018-05-31 15:41   ` [tarantool-patches] Re: [PATCH v1 2/2] sql: use own region in Parser Vladislav Shpilevoy
2018-05-31 15:49     ` Kirill Shcherbatov
2018-05-31 15:41 ` [tarantool-patches] Re: [PATCH v1 0/2] sql: Create special region for parser Vladislav Shpilevoy
2018-05-31 15:50 ` Kirill Shcherbatov
2018-05-31 15:55   ` Vladislav Shpilevoy
2018-05-31 17:43     ` Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=663c4c7deb9d8eff90407f50da2075990b44f815.1527778868.git.kshcherbatov@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH v1 2/2] sql: use own region in Parser' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox