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 130CA21A13 for ; Wed, 18 Jul 2018 04:22:30 -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 5HB907DvubtL for ; Wed, 18 Jul 2018 04:22:29 -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 B40EC216B4 for ; Wed, 18 Jul 2018 04:22:29 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v1 1/1] sql: introduce TRUNCATE TABLE operation Date: Wed, 18 Jul 2018 11:22:26 +0300 Message-Id: <70326bb69fbe25215df79e2d5e01043f93ff7c5a.1531902074.git.kshcherbatov@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: korablev@tarantool.org, Kirill Shcherbatov As sql_table_delete_from already support OP_Clear fast cleanup for non-complex requests we only need to introduce new words to parser that call DELETE with NULL conditions. Closes #2201. --- Branch: http://github.com/tarantool/tarantool/tree/kshch/gh-2201-truncate-table Issue: https://github.com/tarantool/tarantool/issues/2201 extra/mkkeywordhash.c | 1 + src/box/sql/parse.y | 9 +++++++++ test/sql/delete.result | 10 ++++++++++ test/sql/delete.test.lua | 6 ++++++ 4 files changed, 26 insertions(+) diff --git a/extra/mkkeywordhash.c b/extra/mkkeywordhash.c index 1ec1538..705caf1 100644 --- a/extra/mkkeywordhash.c +++ b/extra/mkkeywordhash.c @@ -281,6 +281,7 @@ static Keyword aKeywordTable[] = { { "VARCHAR", "TK_ID", RESERVED, true }, { "WHENEVER", "TK_STANDARD", RESERVED, true }, { "WHILE", "TK_STANDARD", RESERVED, true }, + { "TRUNCATE", "TK_TRUNCATE", ALWAYS, true }, }; /* Number of keywords */ diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y index 0c510f5..2091ce8 100644 --- a/src/box/sql/parse.y +++ b/src/box/sql/parse.y @@ -725,6 +725,15 @@ cmd ::= with(C) DELETE FROM fullname(X) indexed_opt(I) where_opt(W). { sql_table_delete_from(pParse,X,W); } +/////////////////////////// The TRUNCATE statement ///////////////////////////// +// +cmd ::= TRUNCATE TABLE fullname(X). { + sqlSubProgramsRemaining = SQL_MAX_COMPILING_TRIGGERS; + /* Instruct SQL to initate Tarantool's transaction. */ + pParse->initiateTTrans = true; + sql_table_delete_from(pParse, X, NULL); +} + %type where_opt {Expr*} %destructor where_opt {sql_expr_delete(pParse->db, $$, false);} diff --git a/test/sql/delete.result b/test/sql/delete.result index c33079c..6026406 100644 --- a/test/sql/delete.result +++ b/test/sql/delete.result @@ -33,6 +33,16 @@ box.sql.execute("SELECT * FROM t1;"); --- - - [2, 4] ... +-- +-- gh-2201: TRUNCATE TABLE operation +-- +box.sql.execute("TRUNCATE TABLE t1;") +--- +... +box.sql.execute("SELECT * FROM t1;") +--- +- [] +... -- Cleanup box.sql.execute("DROP TABLE t1;"); --- diff --git a/test/sql/delete.test.lua b/test/sql/delete.test.lua index 1721989..7132302 100644 --- a/test/sql/delete.test.lua +++ b/test/sql/delete.test.lua @@ -21,6 +21,12 @@ box.sql.execute("DELETE FROM t1 WHERE a=1;"); -- Verify box.sql.execute("SELECT * FROM t1;"); +-- +-- gh-2201: TRUNCATE TABLE operation +-- +box.sql.execute("TRUNCATE TABLE t1;") +box.sql.execute("SELECT * FROM t1;") + -- Cleanup box.sql.execute("DROP TABLE t1;"); -- 2.7.4