Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH v1 1/1] sql: introduce TRUNCATE TABLE operation
@ 2018-07-18  8:22 Kirill Shcherbatov
  2018-07-18  8:31 ` [tarantool-patches] " Vladislav Shpilevoy
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Kirill Shcherbatov @ 2018-07-18  8:22 UTC (permalink / raw)
  To: tarantool-patches; +Cc: korablev, 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2018-07-27  7:16 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-18  8:22 [tarantool-patches] [PATCH v1 1/1] sql: introduce TRUNCATE TABLE operation Kirill Shcherbatov
2018-07-18  8:31 ` [tarantool-patches] " Vladislav Shpilevoy
2018-07-18 13:01   ` Kirill Shcherbatov
2018-07-18 16:40     ` n.pettik
2018-07-19  9:01       ` Kirill Shcherbatov
2018-07-19 10:00       ` Kirill Shcherbatov
2018-07-20  2:16         ` n.pettik
2018-07-20  8:29           ` Kirill Shcherbatov
2018-07-20 16:33             ` n.pettik
2018-07-23 10:33               ` Kirill Shcherbatov
2018-07-25 12:58                 ` n.pettik
2018-07-25 16:59                   ` Kirill Shcherbatov
2018-07-26  9:10                     ` n.pettik
2018-07-26 20:40 ` Vladislav Shpilevoy
2018-07-27  7:09   ` Kirill Shcherbatov
2018-07-27  7:16 ` Kirill Yukhin

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