From: Kirill Shcherbatov <kshcherbatov@tarantool.org> To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, korablev@tarantool.org, Kirill Shcherbatov <kshcherbatov@tarantool.org> Subject: [tarantool-patches] [PATCH v1 1/2] sql: use schema API to get index info in analyze Date: Tue, 24 Jul 2018 14:05:12 +0300 [thread overview] Message-ID: <aa9d1ac8d749bd0dc5e1f189d8480bdd907d1701.1532430181.git.kshcherbatov@tarantool.org> (raw) In-Reply-To: <5899c7db-b1c0-d099-989e-dcb41b801cdd@tarantool.org> We would like to avoid starting transactions in ANALYZE so we need to use schema API that is more tolerant. Part of #3551. --- src/box/sql/analyze.c | 82 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c index 00d96d2..c7b85dc 100644 --- a/src/box/sql/analyze.c +++ b/src/box/sql/analyze.c @@ -1219,6 +1219,26 @@ decode_stat_string(const char *stat_string, int stat_size, tRowcnt *stat_exact, } /** + * Find index with specified @name in specified @space. + * @param space to lookup. + * @param name to use in comparation. + * @param len lenth of @name string. + * @retval NULL on nothing found. + * @retval not NULL pointer on index AST else. + */ +static struct index * +space_index_by_name(struct space *space, const char *name, uint32_t len) +{ + uint32_t idx_cnt = space->index_count; + for (uint32_t i = 0; i < idx_cnt; i++) { + const char *idx_name = space->index[i]->def->name; + if (strlen(idx_name) == len && memcmp(idx_name, name, len) == 0) + return space->index[i]; + } + return NULL; +} + +/** * This callback is invoked once for each index when reading the * _sql_stat1 table. * @@ -1246,20 +1266,20 @@ analysis_loader(void *data, int argc, char **argv, char **unused) struct analysis_index_info *info = (struct analysis_index_info *) data; assert(info->stats != NULL); struct index_stat *stat = &info->stats[info->index_count++]; - uint32_t space_id = box_space_id_by_name(argv[0], strlen(argv[0])); - if (space_id == BOX_ID_NIL) + uint32_t space_id = BOX_ID_NIL; + int rc = schema_find_id(BOX_SPACE_ID, 2, argv[0], strlen(argv[0]), + &space_id); + if (rc != 0 || space_id == BOX_ID_NIL) return -1; struct space *space = space_by_id(space_id); assert(space != NULL); - struct index *index; - uint32_t iid = box_index_id_by_name(space_id, argv[1], strlen(argv[1])); + struct index *index = + space_index_by_name(space, argv[1], strlen(argv[1])); /* * Convention is if index's name matches with space's * one, then it is primary index. */ - if (iid != BOX_ID_NIL) { - index = space_index(space, iid); - } else { + if (index == NULL) { if (sqlite3_stricmp(argv[0], argv[1]) != 0) return -1; index = space_index(space, 0); @@ -1417,19 +1437,17 @@ load_stat_from_space(struct sqlite3 *db, const char *sql_select_prepare, if (index_name == NULL) continue; uint32_t sample_count = sqlite3_column_int(stmt, 2); - uint32_t space_id = box_space_id_by_name(space_name, - strlen(space_name)); - assert(space_id != BOX_ID_NIL); + uint32_t space_id = BOX_ID_NIL; + rc = schema_find_id(BOX_SPACE_ID, 2, space_name, + strlen(space_name), &space_id); + assert(rc == 0 && space_id != BOX_ID_NIL); struct space *space = space_by_id(space_id); assert(space != NULL); - struct index *index; - uint32_t iid = box_index_id_by_name(space_id, index_name, - strlen(index_name)); + struct index *index = + space_index_by_name(space, index_name, strlen(index_name)); if (sqlite3_stricmp(space_name, index_name) == 0 && - iid == BOX_ID_NIL) + index == NULL) index = space_index(space, 0); - else - index = space_index(space, iid); assert(index != NULL); uint32_t column_count = index->def->key_def->part_count; struct index_stat *stat = &stats[current_idx_count]; @@ -1488,17 +1506,15 @@ load_stat_from_space(struct sqlite3 *db, const char *sql_select_prepare, const char *index_name = (char *)sqlite3_column_text(stmt, 1); if (index_name == NULL) continue; - uint32_t space_id = box_space_id_by_name(space_name, - strlen(space_name)); - assert(space_id != BOX_ID_NIL); + uint32_t space_id = BOX_ID_NIL; + int rc = schema_find_id(BOX_SPACE_ID, 2, space_name, + strlen(space_name), &space_id); + assert(rc == 0 && space_id != BOX_ID_NIL); struct space *space = space_by_id(space_id); assert(space != NULL); - struct index *index; - uint32_t iid = box_index_id_by_name(space_id, index_name, - strlen(index_name)); - if (iid != BOX_ID_NIL) { - index = space_index(space, iid); - } else { + struct index *index = + space_index_by_name(space, index_name, strlen(index_name)); + if (index == NULL) { if (sqlite3_stricmp(space_name, index_name) != 0) return -1; index = space_index(space, 0); @@ -1572,18 +1588,16 @@ load_stat_to_index(struct sqlite3 *db, const char *sql_select_load, const char *index_name = (char *)sqlite3_column_text(stmt, 1); if (index_name == NULL) continue; - uint32_t space_id = box_space_id_by_name(space_name, - strlen(space_name)); - if (space_id == BOX_ID_NIL) + uint32_t space_id = BOX_ID_NIL; + int rc = schema_find_id(BOX_SPACE_ID, 2, space_name, strlen(space_name), + &space_id); + if (rc != 0 || space_id == BOX_ID_NIL) return -1; struct space *space = space_by_id(space_id); assert(space != NULL); - struct index *index; - uint32_t iid = box_index_id_by_name(space_id, index_name, - strlen(index_name)); - if (iid != BOX_ID_NIL) { - index = space_index(space, iid); - } else { + struct index *index = + space_index_by_name(space, index_name, strlen(index_name)); + if (index == NULL) { if (sqlite3_stricmp(space_name, index_name) != 0) return -1; index = space_index(space, 0); -- 2.7.4
next prev parent reply other threads:[~2018-07-24 11:05 UTC|newest] Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-07-20 13:52 [tarantool-patches] [PATCH v1 1/1] sql: prevent executing crossengine sql Kirill Shcherbatov 2018-07-20 15:03 ` [tarantool-patches] " Vladislav Shpilevoy 2018-07-20 17:50 ` Kirill Shcherbatov 2018-07-23 11:50 ` Vladislav Shpilevoy 2018-07-23 16:20 ` n.pettik 2018-07-23 16:39 ` Vladislav Shpilevoy 2018-07-23 17:09 ` n.pettik 2018-07-23 17:21 ` Vladislav Shpilevoy 2018-07-23 18:06 ` n.pettik 2018-07-23 18:29 ` Vladislav Shpilevoy 2018-07-24 11:05 ` Kirill Shcherbatov [this message] [not found] ` <cover.1532430181.git.kshcherbatov@tarantool.org> 2018-07-24 11:05 ` [tarantool-patches] [PATCH v1 2/2] " Kirill Shcherbatov 2018-07-25 13:24 ` [tarantool-patches] " n.pettik 2018-07-25 17:07 ` Kirill Shcherbatov 2018-07-25 21:05 ` Vladislav Shpilevoy 2018-07-26 7:08 ` Kirill Shcherbatov 2018-07-26 8:54 ` Vladislav Shpilevoy 2018-07-26 11:22 ` Kirill Shcherbatov 2018-07-26 21:26 ` Vladislav Shpilevoy 2018-07-27 7:13 ` Kirill Shcherbatov 2018-07-27 8:55 ` Vladislav Shpilevoy 2018-07-27 10:02 ` Kirill Shcherbatov 2018-07-27 10:14 ` Vladislav Shpilevoy 2018-07-31 7:54 ` Kirill Yukhin 2018-07-25 13:22 ` [tarantool-patches] Re: [PATCH v1 1/2] sql: use schema API to get index info in analyze n.pettik 2018-07-25 17:07 ` Kirill Shcherbatov 2018-07-25 20:52 ` Vladislav Shpilevoy
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=aa9d1ac8d749bd0dc5e1f189d8480bdd907d1701.1532430181.git.kshcherbatov@tarantool.org \ --to=kshcherbatov@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [tarantool-patches] [PATCH v1 1/2] sql: use schema API to get index info in analyze' \ /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