diff --git a/src/box/engine_memtx.cc b/src/box/engine_memtx.cc index fd47ba665d69a31d21fe55dfc5b4fca84d37a991..fa9c459ee482373e4e20f868d3888c1b945dabf2 100644 --- a/src/box/engine_memtx.cc +++ b/src/box/engine_memtx.cc @@ -142,9 +142,17 @@ MemtxFactory::keydefCheck(struct key_def *key_def) /* TREE index has no limitations. */ break; case RTREE: - if (key_def->part_count != 1 || key_def->parts[0].type != BOX) { + if (key_def->part_count != 1) { + tnt_raise(ClientError, ER_MODIFY_INDEX, + (unsigned) key_def->iid, + (unsigned) key_def->space_id, + "RTREE index key can not be multipart"); + } + if (key_def->is_unique) { tnt_raise(ClientError, ER_MODIFY_INDEX, - "R-Tree index can be defied only for BOX type"); + (unsigned) key_def->iid, + (unsigned) key_def->space_id, + "RTREE index can not be unique"); } break; case BITSET: @@ -167,4 +175,28 @@ MemtxFactory::keydefCheck(struct key_def *key_def) (unsigned) key_def->space_id); break; } + for (uint32_t i = 0; i < key_def->part_count; i++) { + switch (key_def->parts[i].type) { + case NUM: + case STRING: + if (key_def->type == RTREE) { + tnt_raise(ClientError, ER_MODIFY_INDEX, + (unsigned) key_def->iid, + (unsigned) key_def->space_id, + "RTREE index field type must be ARRAY"); + } + break; + case ARRAY: + if (key_def->type != RTREE) { + tnt_raise(ClientError, ER_MODIFY_INDEX, + (unsigned) key_def->iid, + (unsigned) key_def->space_id, + "ARRAY field type is not supported"); + } + break; + default: + assert(false); + break; + } + } } diff --git a/src/box/engine_sophia.cc b/src/box/engine_sophia.cc index 20a9555196e7656f493456181535adde9e14d226..e1058e6305fef5b257c9cc8cd85a147f32d893d1 100644 --- a/src/box/engine_sophia.cc +++ b/src/box/engine_sophia.cc @@ -202,6 +202,13 @@ SophiaFactory::keydefCheck(struct key_def *key_def) (unsigned) key_def->space_id, "Sophia TREE index key can not be multipart"); } + if (key_def->parts[0].type != NUM && + key_def->parts[0].type != STRING) { + tnt_raise(ClientError, ER_MODIFY_INDEX, + (unsigned) key_def->iid, + (unsigned) key_def->space_id, + "Sophia TREE index field type must be STR or NUM"); + } break; default: tnt_raise(ClientError, ER_INDEX_TYPE, diff --git a/src/box/index.cc b/src/box/index.cc index 4f717db46df909bc95d743eb29d36dd9f80163c8..4d3074d50b07f13d07dc6d3096dc507c2e4a4fe1 100644 --- a/src/box/index.cc +++ b/src/box/index.cc @@ -77,11 +77,13 @@ key_validate(struct key_def *key_def, enum iterator_type type, const char *key, if (part_count != 1 && part_count != 2 && part_count != 4) { tnt_raise(ClientError, ER_KEY_PART_COUNT, 4, part_count); } +#if 0 for (uint32_t part = 0; part < part_count; part++) { enum mp_type mp_type = mp_typeof(*key); mp_next(&key); - key_mp_type_validate(BOX, mp_type, ER_KEY_PART_TYPE, part); + key_mp_type_validate(NUM, mp_type, ER_KEY_PART_TYPE, part); } +#endif } else { if (part_count > key_def->part_count) tnt_raise(ClientError, ER_KEY_PART_COUNT, diff --git a/src/box/key_def.cc b/src/box/key_def.cc index 8dbc59afc4a099deb8dbd48b8d93d96c5c0d546b..0f670e3396dcac2a7f3d7a663a257392c16166b3 100644 --- a/src/box/key_def.cc +++ b/src/box/key_def.cc @@ -33,15 +33,14 @@ #include <stdio.h> #include "exception.h" -const char *field_type_strs[] = {"UNKNOWN", "NUM", "STR", "ARR", "BOX", "\0"}; +const char *field_type_strs[] = {"UNKNOWN", "NUM", "STR", "ARRAY", "\0"}; STRS(index_type, ENUM_INDEX_TYPE); const uint32_t key_mp_type[] = { /* [UNKNOWN] = */ UINT32_MAX, /* [NUM] = */ 1U << MP_UINT, - /* [STR] = */ 1U << MP_STR, - /* [ARR] = */ 1U << MP_ARRAY, - /* [BOX] = */ (1U << MP_UINT)|(1U << MP_INT)|(1U << MP_FLOAT)|(1U << MP_DOUBLE)|(1U << MP_ARRAY) + /* [STR] = */ 1U << MP_STR, + /* [ARRAY] = */ 1U << MP_ARRAY, }; enum schema_object_type diff --git a/src/box/key_def.h b/src/box/key_def.h index 1ede7d9cde59695a1acef74c0143e33adf2db4d9..fb7a3a4b7059256a6f590adebbd42e721b85303e 100644 --- a/src/box/key_def.h +++ b/src/box/key_def.h @@ -75,7 +75,7 @@ schema_object_type(const char *name); * since there is a mismatch between enum name (STRING) and type * name literal ("STR"). STR is already used as Objective C type. */ -enum field_type { UNKNOWN = 0, NUM, STRING, ARR, BOX, field_type_MAX }; +enum field_type { UNKNOWN = 0, NUM, STRING, ARRAY, field_type_MAX }; extern const char *field_type_strs[]; static inline uint32_t diff --git a/src/box/rtree_index.cc b/src/box/rtree_index.cc index f162ff22d384c66ac7cb749cd1e81d0c336cde1f..f8ddddf7e216f5a60ce0be2fadd95921191002b8 100644 --- a/src/box/rtree_index.cc +++ b/src/box/rtree_index.cc @@ -147,16 +147,16 @@ RTreeIndex::~RTreeIndex() RTreeIndex::RTreeIndex(struct key_def *key_def) : Index(key_def) { + assert(key_def->part_count == 1); + assert(key_def->parts[0].type = ARRAY); + assert(key_def->is_unique == false); + if (rtree_page_pool_initialized == 0) { mempool_create(&rtree_page_pool, &cord()->slabc, RTREE_PAGE_SIZE); rtree_page_pool_initialized = 1; } rtree_init(&tree, rtree_page_alloc, rtree_page_free); - if (key_def->part_count != 1 || key_def->parts[0].type != BOX) { - tnt_raise(ClientError, ER_UNSUPPORTED, - "R-Tree index", "Key should have BOX type"); - } } size_t diff --git a/test/box/rtree_array.result b/test/box/rtree_array.result index c4b09d00d5dbc214a7842ea09f2bcfcf7ce392e6..e58a1b45aeadd41caa6edc757bfb44b233dcd870 100644 --- a/test/box/rtree_array.result +++ b/test/box/rtree_array.result @@ -12,11 +12,11 @@ s:create_index('primary') name: primary type: TREE ... -s:create_index('spatial', { type = 'rtree', parts = {2, 'box'}}) +s:create_index('spatial', { type = 'rtree', unique = false, parts = {2, 'array'}}) --- -- unique: true +- unique: false parts: - - type: BOX + - type: ARRAY fieldno: 2 id: 1 space_id: 512 @@ -80,12 +80,12 @@ s.index.spatial:select({0.0,0.0,10.0,10.0}, {iterator = 'LE'}) - [4, [10, 0]] - [6, [10, 10]] ... --- select records with coodinates (10,10) +-- select records with coordinates (10,10) s.index.spatial:select({10.0,10.0}, {iterator = 'EQ'}) --- - - [6, [10, 10]] ... --- select neigbors of point (5,5) +-- select neighbors of point (5,5) s.index.spatial:select({5.0,5.0}, {iterator = 'NEIGHBOR'}) --- - - [6, [10, 10]] diff --git a/test/box/rtree_array.test.lua b/test/box/rtree_array.test.lua index 511208bce1087ca0b578ce36903a476ff9d341ad..1dcecac280e68d8e0d5b02bba4d7e9534b1d9b69 100644 --- a/test/box/rtree_array.test.lua +++ b/test/box/rtree_array.test.lua @@ -1,6 +1,6 @@ s = box.schema.create_space('spatial') s:create_index('primary') -s:create_index('spatial', { type = 'rtree', parts = {2, 'box'}}) +s:create_index('spatial', { type = 'rtree', unique = false, parts = {2, 'array'}}) s:insert{1,{0.0,0.0}} s:insert{2,{0.0,10.0}} @@ -16,9 +16,9 @@ s:insert{9,{50.0,50.0}} s.index.spatial:select({iterator = 'ALL'}) -- select records belonging to rectangle (0,0,10,10) s.index.spatial:select({0.0,0.0,10.0,10.0}, {iterator = 'LE'}) --- select records with coodinates (10,10) +-- select records with coordinates (10,10) s.index.spatial:select({10.0,10.0}, {iterator = 'EQ'}) --- select neigbors of point (5,5) +-- select neighbors of point (5,5) s.index.spatial:select({5.0,5.0}, {iterator = 'NEIGHBOR'}) s:drop() diff --git a/test/box/rtree_point.result b/test/box/rtree_point.result index db76b0b1121191644296a314e64ae5e96ebe1cd7..c011d852ff01c241c55cfa55efb9f7a13d578ff2 100644 --- a/test/box/rtree_point.result +++ b/test/box/rtree_point.result @@ -12,11 +12,11 @@ s:create_index('primary') name: primary type: TREE ... -s:create_index('spatial', { type = 'rtree', parts = {2, 'box'}}) +s:create_index('spatial', { type = 'rtree', unique = false, parts = {2, 'array'}}) --- -- unique: true +- unique: false parts: - - type: BOX + - type: ARRAY fieldno: 2 id: 1 space_id: 512 @@ -80,12 +80,12 @@ s.index.spatial:select({0,0,10,10}, {iterator = 'LE'}) - [4, [10, 0]] - [6, [10, 10]] ... --- select records with coodinates (10,10) +-- select records with coordinates (10,10) s.index.spatial:select({10,10}, {iterator = 'EQ'}) --- - - [6, [10, 10]] ... --- select neigbors of point (5,5) +-- select neighbors of point (5,5) s.index.spatial:select({5,5}, {iterator = 'NEIGHBOR'}) --- - - [6, [10, 10]] diff --git a/test/box/rtree_point.test.lua b/test/box/rtree_point.test.lua index ec2abc66be894c0b594fb934062dc038fd58c648..394a23a5d48d76b99accd906ba229004b93c85e8 100644 --- a/test/box/rtree_point.test.lua +++ b/test/box/rtree_point.test.lua @@ -1,6 +1,6 @@ s = box.schema.create_space('spatial') s:create_index('primary') -s:create_index('spatial', { type = 'rtree', parts = {2, 'box'}}) +s:create_index('spatial', { type = 'rtree', unique = false, parts = {2, 'array'}}) s:insert{1,{0,0}} s:insert{2,{0,10}} @@ -16,9 +16,9 @@ s:insert{9,{50,50}} s.index.spatial:select({iterator = 'ALL'}) -- select records belonging to rectangle (0,0,10,10) s.index.spatial:select({0,0,10,10}, {iterator = 'LE'}) --- select records with coodinates (10,10) +-- select records with coordinates (10,10) s.index.spatial:select({10,10}, {iterator = 'EQ'}) --- select neigbors of point (5,5) +-- select neighbors of point (5,5) s.index.spatial:select({5,5}, {iterator = 'NEIGHBOR'}) s:drop() diff --git a/test/box/rtree_point_r2.result b/test/box/rtree_point_r2.result index c4b09d00d5dbc214a7842ea09f2bcfcf7ce392e6..e58a1b45aeadd41caa6edc757bfb44b233dcd870 100644 --- a/test/box/rtree_point_r2.result +++ b/test/box/rtree_point_r2.result @@ -12,11 +12,11 @@ s:create_index('primary') name: primary type: TREE ... -s:create_index('spatial', { type = 'rtree', parts = {2, 'box'}}) +s:create_index('spatial', { type = 'rtree', unique = false, parts = {2, 'array'}}) --- -- unique: true +- unique: false parts: - - type: BOX + - type: ARRAY fieldno: 2 id: 1 space_id: 512 @@ -80,12 +80,12 @@ s.index.spatial:select({0.0,0.0,10.0,10.0}, {iterator = 'LE'}) - [4, [10, 0]] - [6, [10, 10]] ... --- select records with coodinates (10,10) +-- select records with coordinates (10,10) s.index.spatial:select({10.0,10.0}, {iterator = 'EQ'}) --- - - [6, [10, 10]] ... --- select neigbors of point (5,5) +-- select neighbors of point (5,5) s.index.spatial:select({5.0,5.0}, {iterator = 'NEIGHBOR'}) --- - - [6, [10, 10]] diff --git a/test/box/rtree_point_r2.test.lua b/test/box/rtree_point_r2.test.lua index 511208bce1087ca0b578ce36903a476ff9d341ad..1dcecac280e68d8e0d5b02bba4d7e9534b1d9b69 100644 --- a/test/box/rtree_point_r2.test.lua +++ b/test/box/rtree_point_r2.test.lua @@ -1,6 +1,6 @@ s = box.schema.create_space('spatial') s:create_index('primary') -s:create_index('spatial', { type = 'rtree', parts = {2, 'box'}}) +s:create_index('spatial', { type = 'rtree', unique = false, parts = {2, 'array'}}) s:insert{1,{0.0,0.0}} s:insert{2,{0.0,10.0}} @@ -16,9 +16,9 @@ s:insert{9,{50.0,50.0}} s.index.spatial:select({iterator = 'ALL'}) -- select records belonging to rectangle (0,0,10,10) s.index.spatial:select({0.0,0.0,10.0,10.0}, {iterator = 'LE'}) --- select records with coodinates (10,10) +-- select records with coordinates (10,10) s.index.spatial:select({10.0,10.0}, {iterator = 'EQ'}) --- select neigbors of point (5,5) +-- select neighbors of point (5,5) s.index.spatial:select({5.0,5.0}, {iterator = 'NEIGHBOR'}) s:drop() diff --git a/test/box/rtree_rect.result b/test/box/rtree_rect.result index 1206beeaebd61c261c5beee4d3aae30cfa6c3f3c..c4ee5637cb9b62f4cb3413537e57e38fe1cf8132 100644 --- a/test/box/rtree_rect.result +++ b/test/box/rtree_rect.result @@ -12,11 +12,11 @@ s:create_index('primary') name: primary type: TREE ... -s:create_index('spatial', { type = 'rtree', parts = {2, 'box'}}) +s:create_index('spatial', { type = 'rtree', unique = false, parts = {2, 'array'}}) --- -- unique: true +- unique: false parts: - - type: BOX + - type: ARRAY fieldno: 2 id: 1 space_id: 512 @@ -82,7 +82,7 @@ s.index.spatial:select({0,0,5,5}, {iterator = 'EQ'}) --- - - [3, [0, 0, 5, 5]] ... --- select neigbors of point (1,1) +-- select neighbors of point (1,1) s.index.spatial:select({1,1}, {iterator = 'NEIGHBOR'}) --- - - [3, [0, 0, 5, 5]] diff --git a/test/box/rtree_rect.test.lua b/test/box/rtree_rect.test.lua index a71f0a418bbbca66be28b873fb0d7df9e7e7c14e..3580985e397786e485250532b46c0f4f45ef5083 100644 --- a/test/box/rtree_rect.test.lua +++ b/test/box/rtree_rect.test.lua @@ -1,6 +1,6 @@ s = box.schema.create_space('spatial') s:create_index('primary') -s:create_index('spatial', { type = 'rtree', parts = {2, 'box'}}) +s:create_index('spatial', { type = 'rtree', unique = false, parts = {2, 'array'}}) s:insert{1,{0,0,10,10}{ s:insert{2,{5,5,10,10}} @@ -24,7 +24,7 @@ s.index.spatial:select({0,0,5,5}, {iterator = 'GT'}) s.index.spatial:select({9,4,11,6}, {iterator = 'OVERLAPS'}) -- select records with coordinates (0,0,5,5) s.index.spatial:select({0,0,5,5}, {iterator = 'EQ'}) --- select neigbors of point (1,1) +-- select neighbors of point (1,1) s.index.spatial:select({1,1}, {iterator = 'NEIGHBOR'}) s:drop() diff --git a/test/wal/rtree_benchmark.result b/test/wal/rtree_benchmark.result index 1658290d4f1b52c978acd7642cd40b62c431c2ae..3e9256577421aa52c5e878d61153a154d9dd8c9d 100644 --- a/test/wal/rtree_benchmark.result +++ b/test/wal/rtree_benchmark.result @@ -12,11 +12,11 @@ s:create_index('primary') name: primary type: TREE ... -s:create_index('spatial', { type = 'rtree', parts = {2, 'box'}}) +s:create_index('spatial', { type = 'rtree', unique = false, parts = {2, 'array'}}) --- -- unique: true +- unique: false parts: - - type: BOX + - type: ARRAY fieldno: 2 id: 1 space_id: 512 diff --git a/test/wal/rtree_benchmark.test.lua b/test/wal/rtree_benchmark.test.lua index 5f8457b982aec604aff45b42dd77af9cfaf4941e..07db874218197ec656a267372b526abae0784a5e 100644 --- a/test/wal/rtree_benchmark.test.lua +++ b/test/wal/rtree_benchmark.test.lua @@ -1,6 +1,6 @@ s = box.schema.create_space('rtreebench') s:create_index('primary') -s:create_index('spatial', { type = 'rtree', parts = {2, 'box'}}) +s:create_index('spatial', { type = 'rtree', unique = false, parts = {2, 'array'}}) n_records = 20000 n_iterations = 10000