[tarantool-patches] Re: [PATCH 1/4] sql: optimize compilation of SELECT COUNT(*)
n.pettik
korablev at tarantool.org
Fri May 11 20:29:27 MSK 2018
I have rebased on fresh 2.0, but no significant changes seem to appear.
> 1. In Tarantool 'memtx' count() is not a scan - it is O(1) operation, that simply
> gets current size of the primary index B+ tree. Maybe worth show it in the
> explanation.
Done (alongside, with tests):
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -5259,6 +5259,8 @@ updateAccumulator(Parse * pParse, AggInfo * pAggInfo)
/**
* Add a single OP_Explain instruction to the VDBE to explain
* a simple count(*) query ("SELECT count(*) FROM <tab>").
+ * For memtx engine count is a simple operation,
+ * which takes O(1) complexity.
*
* @param parse_context Current parsing context.
* @param table_name Name of table being queried.
@@ -5267,7 +5269,7 @@ static void
explain_simple_count(struct Parse *parse_context, const char *table_name)
{
if (parse_context->explain == 2) {
- char *zEqp = sqlite3MPrintf(parse_context->db, "SCAN TABLE %s",
+ char *zEqp = sqlite3MPrintf(parse_context->db, "B+tree count %s”,
==============================================================================
diff --git a/test/sql-tap/eqp.test.lua b/test/sql-tap/eqp.test.lua
index 468bca0a7..15d428814 100755
--- a/test/sql-tap/eqp.test.lua
+++ b/test/sql-tap/eqp.test.lua
@@ -733,10 +733,10 @@ test:do_execsql_test(
]])
test:do_eqp_test(7.1, "SELECT count(*) FROM t1", {
- {0, 0, 0, "SCAN TABLE T1"},
+ {0, 0, 0, "B+tree count T1"},
})
test:do_eqp_test(7.2, "SELECT count(*) FROM t2", {
- {0, 0, 0, "SCAN TABLE T2"},
+ {0, 0, 0, "B+tree count T2"},
})
-- MUST_WORK_TEST
if (0 > 0)
@@ -781,7 +781,7 @@ test:do_eqp_test("8.1.1", "SELECT * FROM t2", {
-- {0, 0, 0, "SEARCH TABLE T2 USING INTEGER PRIMARY KEY (rowid=?)"},
-- }
test:do_eqp_test("8.1.3", "SELECT count(*) FROM t2", {
- {0, 0, 0, "SCAN TABLE T2"},
+ {0, 0, 0, "B+tree count T2"},
})
test:do_eqp_test("8.2.1", "SELECT * FROM t1", {
{0, 0, 0, "SCAN TABLE T1"},
@@ -793,7 +793,7 @@ test:do_eqp_test("8.2.3", "SELECT * FROM t1 WHERE b=? AND c=?", {
{0, 0, 0, "SEARCH TABLE T1 USING PRIMARY KEY (B=? AND C=?)"},
})
test:do_eqp_test("8.2.4", "SELECT count(*) FROM t1", {
- {0, 0, 0, "SCAN TABLE T1"},
+ {0, 0, 0, "B+tree count T1"},
})
More information about the Tarantool-patches
mailing list