From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 8E9C06EC5D; Fri, 9 Apr 2021 19:52:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8E9C06EC5D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617987142; bh=dhRmzslwyIfTvKadRAhqxmDYBHkM5b9rOcas/x28CdE=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=HwCOuUMFjBCZu/XkrqvEZdI0uZizAHiVm3wU25ppaQKKdmMTA1xO7YnL7jBmOmSEC N8A5wYGqvvwd14OD8j/BDIuwBGCq9q027GPT8BzWbOFIO+jnPiLV/1UZw+ONzuKqtQ z1xOTs8cfLFhIbDsb9H7tNTUYoMBS1DarRLGtijM= Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 81CF46EC5D for ; Fri, 9 Apr 2021 19:51:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 81CF46EC5D Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1lUuLy-00060P-PV; Fri, 09 Apr 2021 19:51:31 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 9 Apr 2021 19:51:30 +0300 Message-Id: <5b13ff9c8a9ba5127e6660af564bc03632a63ded.1617984948.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480257C85EA0BB7A95D5E28B957962BB550182A05F53808504019FE77D0759FD0266EEB4496FE373D229202AE1226D7879887B0010C223FC4C8 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE769902458A0176050EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006374B2D40F594293EAD8638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B26F20673E327C033BEC456C7F92A0EA3716A3AA18C56759C2D2E47CDBA5A96583C09775C1D3CA48CF17B107DEF921CE79117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE71AE4D56B06699BBC9FA2833FD35BB23DF004C906525384302BEBFE083D3B9BA73A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735C6EABA9B74D0DA47B5C8C57E37DE458BEDA766A37F9254B7 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2AD77751E876CB595E8F7B195E1C97831AE293D23B2E582FDBE75460A6CDB2857 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CD0035DD76F8A8A4F804BD500E3D4FCC178291D4F335C4DB39C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3450C5E6D685282BA1DF4B6A3867957BF3611B3174CEC021C2E656712FAEB3CA15144C8CCF7D1EFCD21D7E09C32AA3244C51E4C243A8B6AF92485A8BF874077B77F2F5F14F68F1805BFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojyO2lHpuZu4ROJBYXEtiz3g== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822AADE3763EF10A9114809A8EC1D78B70783D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v5 02/52] sql: disable unused code in sql/analyze.c X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This patch disables unused code in sql/analyze.c. It will simplify refactoring. Needed for #5818 --- src/box/sql.c | 95 +++++++++++++++++++++++++++++++++++-------- src/box/sql.h | 8 ---- src/box/sql/analyze.c | 81 ++---------------------------------- src/box/sql/vdbe.c | 3 ++ 4 files changed, 84 insertions(+), 103 deletions(-) diff --git a/src/box/sql.c b/src/box/sql.c index 3b53abcdb..aa91f003f 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -78,24 +78,6 @@ sql_init(void) assert(db != NULL); } -void -sql_load_schema(void) -{ - assert(db->init.busy == 0); - struct space *stat = space_by_name("_sql_stat1"); - assert(stat != NULL); - if (stat->def->field_count == 0) - return; - db->init.busy = 1; - if (sql_analysis_load(db) != 0) { - if(!diag_is_empty(&fiber()->diag)) { - diag_log(); - } - panic("failed to initialize SQL subsystem"); - } - db->init.busy = 0; -} - sql * sql_get(void) { @@ -1317,3 +1299,80 @@ vdbe_field_ref_prepare_tuple(struct vdbe_field_ref *field_ref, vdbe_field_ref_create(field_ref, tuple, tuple_data(tuple), tuple->bsize); } + +ssize_t +sql_index_tuple_size(struct space *space, struct index *idx) +{ + assert(space != NULL); + assert(idx != NULL); + assert(idx->def->space_id == space->def->id); + ssize_t tuple_count = index_size(idx); + ssize_t space_size = space_bsize(space); + ssize_t avg_tuple_size = tuple_count != 0 ? + (space_size / tuple_count) : 0; + return avg_tuple_size; +} + +/** + * default_tuple_est[] array contains default information + * which is used when we don't have real space, e.g. temporary + * objects representing result set of nested SELECT or VIEW. + * + * First number is supposed to contain the number of elements + * in the index. Since we do not know, guess 1 million. + * Second one is an estimate of the number of rows in the + * table that match any particular value of the first column of + * the index. Third one is an estimate of the number of + * rows that match any particular combination of the first 2 + * columns of the index. And so on. It must always be true: + * + * default_tuple_est[N] <= default_tuple_est[N-1] + * default_tuple_est[N] >= 1 + * + * Apart from that, we have little to go on besides intuition + * as to how default values should be initialized. The numbers + * generated here are based on typical values found in actual + * indices. + */ +const log_est_t default_tuple_est[] = {DEFAULT_TUPLE_LOG_COUNT, +/** [10*log_{2}(x)]: 10, 9, 8, 7, 6, 5 */ + 33, 32, 30, 28, 26, 23}; + +LogEst +sql_space_tuple_log_count(struct space *space) +{ + if (space == NULL || space->index_map == NULL) + return 0; + + struct index *pk = space_index(space, 0); + assert(sqlLogEst(DEFAULT_TUPLE_COUNT) == DEFAULT_TUPLE_LOG_COUNT); + /* If space represents VIEW, return default number. */ + if (pk == NULL) + return DEFAULT_TUPLE_LOG_COUNT; + return sqlLogEst(pk->vtab->size(pk)); +} + +log_est_t +index_field_tuple_est(const struct index_def *idx_def, uint32_t field) +{ + assert(idx_def != NULL); + struct space *space = space_by_id(idx_def->space_id); + if (space == NULL || strcmp(idx_def->name, "fake_autoindex") == 0) + return idx_def->opts.stat->tuple_log_est[field]; + assert(field <= idx_def->key_def->part_count); + /* Statistics is held only in real indexes. */ + struct index *tnt_idx = space_index(space, idx_def->iid); + assert(tnt_idx != NULL); + if (tnt_idx->def->opts.stat == NULL) { + /* + * Last number for unique index is always 0: + * only one tuple exists with given full key + * in unique index and log(1) == 0. + */ + if (field == idx_def->key_def->part_count && + idx_def->opts.is_unique) + return 0; + return default_tuple_est[field + 1 >= 6 ? 6 : field]; + } + return tnt_idx->def->opts.stat->tuple_log_est[field]; +} diff --git a/src/box/sql.h b/src/box/sql.h index f56f7a1f1..4c364306c 100644 --- a/src/box/sql.h +++ b/src/box/sql.h @@ -41,14 +41,6 @@ extern "C" { void sql_init(void); -/** - * Initialize SQL statistic system. - * - * Currently unused. - */ -void -sql_load_schema(void); - /** * struct sql * * sql_get(); diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c index f74f9b358..a015f70cb 100644 --- a/src/box/sql/analyze.c +++ b/src/box/sql/analyze.c @@ -116,6 +116,8 @@ #include "tarantoolInt.h" #include "vdbeInt.h" +#if 0 + /** * This routine generates code that opens the sql_stat1/4 tables. * If the sql_statN tables do not previously exist, they are @@ -1114,19 +1116,6 @@ sqlAnalyze(Parse * pParse, Token * pName) sqlVdbeAddOp0(v, OP_Expire); } -ssize_t -sql_index_tuple_size(struct space *space, struct index *idx) -{ - assert(space != NULL); - assert(idx != NULL); - assert(idx->def->space_id == space->def->id); - ssize_t tuple_count = index_size(idx); - ssize_t space_size = space_bsize(space); - ssize_t avg_tuple_size = tuple_count != 0 ? - (space_size / tuple_count) : 0; - return avg_tuple_size; -} - /** * Used to pass information from the analyzer reader through * to the callback routine. @@ -1538,70 +1527,6 @@ load_stat_to_index(const char *sql_select_load, struct index_stat **stats) return 0; } -/** - * default_tuple_est[] array contains default information - * which is used when we don't have real space, e.g. temporary - * objects representing result set of nested SELECT or VIEW. - * - * First number is supposed to contain the number of elements - * in the index. Since we do not know, guess 1 million. - * Second one is an estimate of the number of rows in the - * table that match any particular value of the first column of - * the index. Third one is an estimate of the number of - * rows that match any particular combination of the first 2 - * columns of the index. And so on. It must always be true: - * - * default_tuple_est[N] <= default_tuple_est[N-1] - * default_tuple_est[N] >= 1 - * - * Apart from that, we have little to go on besides intuition - * as to how default values should be initialized. The numbers - * generated here are based on typical values found in actual - * indices. - */ -const log_est_t default_tuple_est[] = {DEFAULT_TUPLE_LOG_COUNT, -/** [10*log_{2}(x)]: 10, 9, 8, 7, 6, 5 */ - 33, 32, 30, 28, 26, 23}; - -LogEst -sql_space_tuple_log_count(struct space *space) -{ - if (space == NULL || space->index_map == NULL) - return 0; - - struct index *pk = space_index(space, 0); - assert(sqlLogEst(DEFAULT_TUPLE_COUNT) == DEFAULT_TUPLE_LOG_COUNT); - /* If space represents VIEW, return default number. */ - if (pk == NULL) - return DEFAULT_TUPLE_LOG_COUNT; - return sqlLogEst(pk->vtab->size(pk)); -} - -log_est_t -index_field_tuple_est(const struct index_def *idx_def, uint32_t field) -{ - assert(idx_def != NULL); - struct space *space = space_by_id(idx_def->space_id); - if (space == NULL || strcmp(idx_def->name, "fake_autoindex") == 0) - return idx_def->opts.stat->tuple_log_est[field]; - assert(field <= idx_def->key_def->part_count); - /* Statistics is held only in real indexes. */ - struct index *tnt_idx = space_index(space, idx_def->iid); - assert(tnt_idx != NULL); - if (tnt_idx->def->opts.stat == NULL) { - /* - * Last number for unique index is always 0: - * only one tuple exists with given full key - * in unique index and log(1) == 0. - */ - if (field == idx_def->key_def->part_count && - idx_def->opts.is_unique) - return 0; - return default_tuple_est[field + 1 >= 6 ? 6 : field]; - } - return tnt_idx->def->opts.stat->tuple_log_est[field]; -} - /** * This function performs copy of statistics. * In contrast to index_stat_dup(), there is no assumption @@ -1744,3 +1669,5 @@ fail: box_txn_rollback(); return -1; } + +#endif diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 9a4f38bb9..4c1cd582b 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -4825,8 +4825,11 @@ case OP_RenameTable: { */ case OP_LoadAnalysis: { assert(pOp->p1==0 ); + /* TODO: Enable analysis. */ + /* if (sql_analysis_load(db) != 0) goto abort_due_to_error; + */ break; } -- 2.25.1