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 5E9E022015 for ; Tue, 24 Apr 2018 08:51:51 -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 1uC5iLckdCiu for ; Tue, 24 Apr 2018 08:51:51 -0400 (EDT) Received: from smtp59.i.mail.ru (smtp59.i.mail.ru [217.69.128.39]) (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 8E56E21FD7 for ; Tue, 24 Apr 2018 08:51:50 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH 1/4] sql: optimize compilation of SELECT COUNT(*) References: <45c716b50ab9dd7405c1d8c20b86abbd639b5f25.1524515002.git.korablev@tarantool.org> From: Vladislav Shpilevoy Message-ID: <408fa156-ccbd-5743-8b31-9daa80c47b26@tarantool.org> Date: Tue, 24 Apr 2018 15:51:46 +0300 MIME-Version: 1.0 In-Reply-To: <45c716b50ab9dd7405c1d8c20b86abbd639b5f25.1524515002.git.korablev@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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: Nikita Pettik , tarantool-patches@freelists.org See my 1 comment below. And please, rebase on the latest 2.0 - maybe some parts of your patchset will become simpler. On 23/04/2018 23:29, Nikita Pettik wrote: > Originally, SQLite chooses the best index to perform COUNT operation. > In Tarantool there is no any considerable difference between them, > so lets don't spend time on this routine and choose always primary index, > in case of simple query 'SELECT COUNT(*) FROM '. > Also, patch contains codestyle fixes. > --- > src/box/sql/select.c | 172 ++++++++++++++++++---------------------------- > src/box/sql/vdbe.c | 2 - > test/sql-tap/eqp.test.lua | 2 +- > 3 files changed, 68 insertions(+), 108 deletions(-) > > diff --git a/src/box/sql/select.c b/src/box/sql/select.c > index d97e466b5..0df8a71d4 100644 > --- a/src/box/sql/select.c > +++ b/src/box/sql/select.c > @@ -5294,25 +5296,23 @@ updateAccumulator(Parse * pParse, AggInfo * pAggInfo) > } > } > > -/* > - * Add a single OP_Explain instruction to the VDBE to explain a simple > - * count(*) query ("SELECT count(*) FROM pTab"). > +/** > + * Add a single OP_Explain instruction to the VDBE to explain > + * a simple count(*) query ("SELECT count(*) FROM "). > + * > + * @param parse_context Current parsing context. > + * @param table_name Name of table being queried. > */ > #ifndef SQLITE_OMIT_EXPLAIN> static void > -explainSimpleCount(Parse * pParse, /* Parse context */ > - Table * pTab, /* Table being queried */ > - Index * pIdx) /* Index used to optimize scan, or NULL */ > +explain_simple_count(struct Parse *parse_context, const char *table_name) > { > - if (pParse->explain == 2) { > - int bCover = (pIdx != 0 && !IsPrimaryKeyIndex(pIdx)); > - char *zEqp = sqlite3MPrintf(pParse->db, "SCAN TABLE %s%s%s", 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.