From f1a75fe4eca4582fa4c9edd326b5edb3ce658ea8 Mon Sep 17 00:00:00 2001 From: Vladimir Davydov <vdavydov.dev@gmail.com> Date: Tue, 17 Oct 2017 16:08:58 +0300 Subject: [PATCH] space: drop execute_select virtual method This virtual method was added to make use of the 'position' optimization implemented in memtx. Since the optimization was removed recently, we don't need it anymore. --- src/box/box.cc | 53 ++++++++++++++++++++++++++++++++++-- src/box/memtx_space.c | 58 ---------------------------------------- src/box/space.c | 52 ----------------------------------- src/box/space.h | 36 ------------------------- src/box/sysview_engine.c | 1 - src/box/vinyl_space.c | 1 - 6 files changed, 51 insertions(+), 150 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index e6638e2f4b..2da4d688bd 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -793,17 +793,66 @@ box_select(struct port *port, uint32_t space_id, uint32_t index_id, int iterator, uint32_t offset, uint32_t limit, const char *key, const char *key_end) { + (void)key_end; + rmean_collect(rmean_box, IPROTO_SELECT, 1); + + if (iterator >= iterator_type_MAX) { + diag_set(ClientError, ER_ILLEGAL_PARAMS, + "Invalid iterator type"); + diag_log(); + return -1; + } + struct space *space = space_cache_find(space_id); if (space == NULL) return -1; if (access_check_space(space, PRIV_R) != 0) return -1; + struct index *index = index_find(space, index_id); + if (index == NULL) + return -1; + + enum iterator_type type = (enum iterator_type) iterator; + uint32_t part_count = key ? mp_decode_array(&key) : 0; + if (key_validate(index->def, type, key, part_count)) + return -1; + + ERROR_INJECT(ERRINJ_TESTING, { + diag_set(ClientError, ER_INJECTION, "ERRINJ_TESTING"); + return -1; + }); + struct txn *txn; if (txn_begin_ro_stmt(space, &txn) != 0) return -1; - if (space_execute_select(space, txn, index_id, iterator, - offset, limit, key, key_end, port) != 0) { + + struct iterator *it = index_create_iterator(index, type, + key, part_count); + if (it == NULL) { + txn_rollback_stmt(); + return -1; + } + + int rc = 0; + uint32_t found = 0; + struct tuple *tuple; + while (found < limit) { + rc = it->next(it, &tuple); + if (rc != 0 || tuple == NULL) + break; + if (offset > 0) { + offset--; + continue; + } + rc = port_add_tuple(port, tuple); + if (rc != 0) + break; + found++; + } + it->free(it); + + if (rc != 0) { txn_rollback_stmt(); return -1; } diff --git a/src/box/memtx_space.c b/src/box/memtx_space.c index 6dba29517a..0b05d3c8bf 100644 --- a/src/box/memtx_space.c +++ b/src/box/memtx_space.c @@ -39,7 +39,6 @@ #include "memtx_tree.h" #include "memtx_rtree.h" #include "memtx_bitset.h" -#include "port.h" #include "memtx_tuple.h" #include "column_mask.h" #include "sequence.h" @@ -511,62 +510,6 @@ memtx_space_execute_upsert(struct space *space, struct txn *txn, return 0; } -static int -memtx_space_execute_select(struct space *space, struct txn *txn, - uint32_t index_id, uint32_t iterator, - uint32_t offset, uint32_t limit, - const char *key, const char *key_end, - struct port *port) -{ - (void)txn; - (void)key_end; - - struct index *index = index_find(space, index_id); - if (index == NULL) - return -1; - - ERROR_INJECT(ERRINJ_TESTING, { - diag_set(ClientError, ER_INJECTION, "ERRINJ_TESTING"); - return -1; - }); - - uint32_t found = 0; - if (iterator >= iterator_type_MAX) { - diag_set(ClientError, ER_ILLEGAL_PARAMS, - "Invalid iterator type"); - diag_log(); - return -1; - } - enum iterator_type type = (enum iterator_type) iterator; - - uint32_t part_count = key ? mp_decode_array(&key) : 0; - if (key_validate(index->def, type, key, part_count)) - return -1; - - struct iterator *it = index_create_iterator(index, type, - key, part_count); - if (it == NULL) - return -1; - - int rc = 0; - struct tuple *tuple; - while (found < limit) { - rc = it->next(it, &tuple); - if (rc != 0 || tuple == NULL) - break; - if (offset > 0) { - offset--; - continue; - } - rc = port_add_tuple(port, tuple); - if (rc != 0) - break; - found++; - } - it->free(it); - return rc; -} - /* }}} DML */ /* {{{ DDL */ @@ -951,7 +894,6 @@ static const struct space_vtab memtx_space_vtab = { /* .execute_delete = */ memtx_space_execute_delete, /* .execute_update = */ memtx_space_execute_update, /* .execute_upsert = */ memtx_space_execute_upsert, - /* .execute_select = */ memtx_space_execute_select, /* .init_system_space = */ memtx_init_system_space, /* .check_index_def = */ memtx_space_check_index_def, /* .create_index = */ memtx_space_create_index, diff --git a/src/box/space.c b/src/box/space.c index c643ae8f82..703270361f 100644 --- a/src/box/space.c +++ b/src/box/space.c @@ -36,7 +36,6 @@ #include "trigger.h" #include "user.h" #include "session.h" -#include "port.h" #include "xrow.h" #include "iproto_constants.h" #include "sequence.h" @@ -242,57 +241,6 @@ index_name_by_id(struct space *space, uint32_t id) return NULL; } -int -generic_space_execute_select(struct space *space, struct txn *txn, - uint32_t index_id, uint32_t iterator, - uint32_t offset, uint32_t limit, - const char *key, const char *key_end, - struct port *port) -{ - (void)txn; - (void)key_end; - - struct index *index = index_find(space, index_id); - if (index == NULL) - return -1; - - uint32_t found = 0; - if (iterator >= iterator_type_MAX) { - diag_set(ClientError, ER_ILLEGAL_PARAMS, - "Invalid iterator type"); - diag_log(); - return -1; - } - enum iterator_type type = (enum iterator_type) iterator; - - uint32_t part_count = key ? mp_decode_array(&key) : 0; - if (key_validate(index->def, type, key, part_count)) - return -1; - - struct iterator *it = index_create_iterator(index, type, - key, part_count); - if (it == NULL) - return -1; - - int rc = 0; - struct tuple *tuple; - while (found < limit) { - rc = it->next(it, &tuple); - if (rc != 0 || tuple == NULL) - break; - if (offset > 0) { - offset--; - continue; - } - rc = port_add_tuple(port, tuple); - if (rc != 0) - break; - found++; - } - it->free(it); - return rc; -} - int space_def_check_compatibility(const struct space_def *old_def, const struct space_def *new_def, diff --git a/src/box/space.h b/src/box/space.h index dabb97ec3a..17ecbb31c5 100644 --- a/src/box/space.h +++ b/src/box/space.h @@ -64,11 +64,6 @@ struct space_vtab { int (*execute_update)(struct space *, struct txn *, struct request *, struct tuple **result); int (*execute_upsert)(struct space *, struct txn *, struct request *); - int (*execute_select)(struct space *space, struct txn *txn, - uint32_t index_id, uint32_t iterator, - uint32_t offset, uint32_t limit, - const char *key, const char *key_end, - struct port *port); void (*init_system_space)(struct space *); /** @@ -334,17 +329,6 @@ int space_execute_upsert(struct space *space, struct txn *txn, struct request *request); -static inline int -space_execute_select(struct space *space, struct txn *txn, - uint32_t index_id, uint32_t iterator, - uint32_t offset, uint32_t limit, - const char *key, const char *key_end, - struct port *port) -{ - return space->vtab->execute_select(space, txn, index_id, iterator, - offset, limit, key, key_end, port); -} - static inline void init_system_space(struct space *space) { @@ -419,14 +403,6 @@ space_commit_alter(struct space *old_space, struct space *new_space) new_space->vtab->commit_alter(old_space, new_space); } -/** Generic implementation of space_vtab::execute_select method. */ -int -generic_space_execute_select(struct space *space, struct txn *txn, - uint32_t index_id, uint32_t iterator, - uint32_t offset, uint32_t limit, - const char *key, const char *key_end, - struct port *port); - static inline bool space_is_memtx(struct space *space) { return space->engine->id == 0; } @@ -580,18 +556,6 @@ space_execute_upsert_xc(struct space *space, struct txn *txn, diag_raise(); } -static inline void -space_execute_select_xc(struct space *space, struct txn *txn, - uint32_t index_id, uint32_t iterator, - uint32_t offset, uint32_t limit, - const char *key, const char *key_end, - struct port *port) -{ - if (space_execute_select(space, txn, index_id, iterator, - offset, limit, key, key_end, port) != 0) - diag_raise(); -} - static inline void space_check_index_def_xc(struct space *space, struct index_def *index_def) { diff --git a/src/box/sysview_engine.c b/src/box/sysview_engine.c index 8d33ddd6d5..6f7c2c87ee 100644 --- a/src/box/sysview_engine.c +++ b/src/box/sysview_engine.c @@ -193,7 +193,6 @@ static const struct space_vtab sysview_space_vtab = { /* .execute_delete = */ sysview_space_execute_delete, /* .execute_update = */ sysview_space_execute_update, /* .execute_upsert = */ sysview_space_execute_upsert, - /* .execute_select = */ generic_space_execute_select, /* .init_system_space = */ sysview_init_system_space, /* .check_index_def = */ sysview_space_check_index_def, /* .create_index = */ sysview_space_create_index, diff --git a/src/box/vinyl_space.c b/src/box/vinyl_space.c index 795de57309..a203cd1c5a 100644 --- a/src/box/vinyl_space.c +++ b/src/box/vinyl_space.c @@ -327,7 +327,6 @@ static const struct space_vtab vinyl_space_vtab = { /* .execute_delete = */ vinyl_space_execute_delete, /* .execute_update = */ vinyl_space_execute_update, /* .execute_upsert = */ vinyl_space_execute_upsert, - /* .execute_select = */ generic_space_execute_select, /* .init_system_space = */ vinyl_init_system_space, /* .check_index_def = */ vinyl_space_check_index_def, /* .create_index = */ vinyl_space_create_index, -- GitLab