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 695E32520C for ; Fri, 11 May 2018 13:29:31 -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 t8Qlf1ADmMrQ for ; Fri, 11 May 2018 13:29:31 -0400 (EDT) Received: from smtp50.i.mail.ru (smtp50.i.mail.ru [94.100.177.110]) (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 B398B25207 for ; Fri, 11 May 2018 13:29:30 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [tarantool-patches] Re: [PATCH 1/4] sql: optimize compilation of SELECT COUNT(*) From: n.pettik In-Reply-To: <408fa156-ccbd-5743-8b31-9daa80c47b26@tarantool.org> Date: Fri, 11 May 2018 20:29:27 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <1460E795-8D3C-49AD-B322-F74C0D81225E@tarantool.org> References: <45c716b50ab9dd7405c1d8c20b86abbd639b5f25.1524515002.git.korablev@tarantool.org> <408fa156-ccbd-5743-8b31-9daa80c47b26@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: Vladislav Shpilevoy 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 "). + * 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 =3D=3D 2) { - char *zEqp =3D sqlite3MPrintf(parse_context->db, "SCAN = TABLE %s", + char *zEqp =3D sqlite3MPrintf(parse_context->db, "B+tree = count %s=E2=80=9D, = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D 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( ]]) =20 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=3D?)"}, -- } 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=3D? AND c=3D?", { {0, 0, 0, "SEARCH TABLE T1 USING PRIMARY KEY (B=3D? AND C=3D?)"}, }) test:do_eqp_test("8.2.4", "SELECT count(*) FROM t1", { - {0, 0, 0, "SCAN TABLE T1"}, + {0, 0, 0, "B+tree count T1"}, })=