Tarantool development patches archive
 help / color / mirror / Atom feed
From: n.pettik <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH 1/4] sql: optimize compilation of SELECT COUNT(*)
Date: Fri, 11 May 2018 20:29:27 +0300	[thread overview]
Message-ID: <1460E795-8D3C-49AD-B322-F74C0D81225E@tarantool.org> (raw)
In-Reply-To: <408fa156-ccbd-5743-8b31-9daa80c47b26@tarantool.org>

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"},
 })

  reply	other threads:[~2018-05-11 17:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-23 20:29 [tarantool-patches] [PATCH 0/4] Move original SQLite's statistics to server Nikita Pettik
2018-04-23 20:29 ` [tarantool-patches] [PATCH 1/4] sql: optimize compilation of SELECT COUNT(*) Nikita Pettik
2018-04-24 12:51   ` [tarantool-patches] " Vladislav Shpilevoy
2018-05-11 17:29     ` n.pettik [this message]
2018-04-23 20:29 ` [tarantool-patches] [PATCH 2/4] sql: add average tuple size calculation Nikita Pettik
2018-04-24 12:51   ` [tarantool-patches] " Vladislav Shpilevoy
2018-05-11 17:29     ` n.pettik
2018-04-23 20:29 ` [tarantool-patches] [PATCH 3/4] sql: refactor usages of table's tuple count Nikita Pettik
2018-04-24 12:51   ` [tarantool-patches] " Vladislav Shpilevoy
2018-05-11 17:29     ` n.pettik
2018-04-23 20:29 ` [tarantool-patches] [PATCH 4/4] sql: move SQL statistics to server Nikita Pettik
2018-04-24 12:51   ` [tarantool-patches] " Vladislav Shpilevoy
2018-05-11 17:29     ` n.pettik
2018-05-11 22:00       ` Vladislav Shpilevoy
2018-05-14 11:52         ` n.pettik
2018-05-14 12:54           ` Vladislav Shpilevoy
2018-05-14 13:55             ` n.pettik
2018-05-14 14:12 ` [tarantool-patches] Re: [PATCH 0/4] Move original SQLite's " Vladislav Shpilevoy
2018-05-15 13:42   ` 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=1460E795-8D3C-49AD-B322-F74C0D81225E@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='[tarantool-patches] Re: [PATCH 1/4] sql: optimize compilation of SELECT COUNT(*)' \
    /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