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 623ED6FC8F; Tue, 23 Mar 2021 12:35:42 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 623ED6FC8F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616492142; 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=nl4c1UR7GfpBsd4nlV1dvf3D7gPG5A4DYCdzGI+PwiRmHLkZmSTYyH3bFyq5+Llbx nr5G9f9fuBLKDG69CoaY9r/GD2pBIeFBEfJ9q0aCFbfNIwG0gZeSPh2c86C4UgWf5q fZUBfGAyzyiBSzzay+N2j/6xSgETmIppKalVZAQ8= Received: from smtp42.i.mail.ru (smtp42.i.mail.ru [94.100.177.102]) (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 E71CB6FC8F for ; Tue, 23 Mar 2021 12:34:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E71CB6FC8F Received: by smtp42.i.mail.ru with esmtpa (envelope-from ) id 1lOdR7-0000Uq-0Z; Tue, 23 Mar 2021 12:34:53 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 23 Mar 2021 12:34:42 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD95D6E7CC48CB1F5F19D4B90E2C0E110A6B701D7D268243E19182A05F538085040D92D6BDE54ED6C89AA9BFC0FB4C03D85FD72C333A27764D346D7FBB688A2FC9C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F10A50E66C9A7FE8C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE728A881FD0F09D355EA1F7E6F0F101C67CDEEF6D7F21E0D1D174C73DBBBFC7664D54267400E4E38EC515ED2926F725BEDD9FDE8F7EA6A0AF1389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C07E7E81EEA8A9722B8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B6D082881546D93491CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C22492B38D3F07E1651EC76E601842F6C81A12EF20D2F80756B5F7E9C4E3C761E06A776E601842F6C81A127C277FBC8AE2E8B94095889EE994E0C3AA81AA40904B5D9DBF02ECDB25306B2201CA6A4E26CD07C3BBE47FD9DD3FB595F5C1EE8F4F765FC72CEEB2601E22B091A620F70A64A45A99449624AB7ADAF3735872C767BF85DA29E625A9149C048EE0A3850AC1BE2E7359EF166FBCB559E954AD6D5ED66289B524E70A05D1297E1BB35872C767BF85DA227C277FBC8AE2E8BF783223E2FFF4BA875ECD9A6C639B01B4E70A05D1297E1BBC6867C52282FAC85D9B7C4F32B44FF57D4B828FA1BC0F1ACBD9CCCA9EDD067B1EDA766A37F9254B7 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A24A6D60772A99906F8E1CD14B953EB46D44BA247731D59183355D89D7DBCDD132 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C686AF563A045C75EEDFDB1E22C5E1FD688D3AACF92442CE29C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3475AE8838CC1BF58EB1D8FA77C2B9F08732E2A8070648D2170F8288271069BFB3AF32FF24946FF7C61D7E09C32AA3244CDEC0909A58A7E9F4C8E194213C4012E563871F383B54D9B3FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojWJZv20R+6UiYVkEG0yxJJA== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306EDAD4FB163AE6E799DAA9BFC0FB4C03D856ECF975C7BB2667F5105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 02/53] 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