|
| 1 | +local select_plan = require('crud.select.plan') |
| 2 | + |
| 3 | +local select_conditions = require('crud.select.conditions') |
| 4 | +local cond_funcs = select_conditions.funcs |
| 5 | + |
| 6 | +local t = require('luatest') |
| 7 | +local g = t.group('select_dropped_indexes') |
| 8 | + |
| 9 | +local helpers = require('test.helper') |
| 10 | + |
| 11 | +g.before_all = function() |
| 12 | + helpers.box_cfg() |
| 13 | + |
| 14 | + local customers = box.schema.space.create('customers', { |
| 15 | + format = { |
| 16 | + {'id', 'unsigned'}, |
| 17 | + {'bucket_id', 'unsigned'}, |
| 18 | + {'name', 'string'}, |
| 19 | + {'age', 'unsigned'}, |
| 20 | + {'number_of_pets', 'unsigned'}, |
| 21 | + {'cars', 'array'}, |
| 22 | + }, |
| 23 | + if_not_exists = true, |
| 24 | + }) |
| 25 | + |
| 26 | + customers:create_index('index1', { |
| 27 | + type = 'TREE', |
| 28 | + parts = {'id'}, |
| 29 | + if_not_exists = true, |
| 30 | + }) |
| 31 | + |
| 32 | + customers:create_index('index2', { |
| 33 | + parts = {'bucket_id'}, |
| 34 | + unique = false, |
| 35 | + if_not_exists = true, |
| 36 | + }) |
| 37 | + |
| 38 | + customers:create_index('index3', { |
| 39 | + type = 'TREE', |
| 40 | + parts = {'age'}, |
| 41 | + unique = false, |
| 42 | + if_not_exists = true, |
| 43 | + }) |
| 44 | + |
| 45 | + customers:create_index('index4_dropped', { |
| 46 | + type = 'HASH', |
| 47 | + parts = {'name'}, |
| 48 | + if_not_exists = true, |
| 49 | + }) |
| 50 | + |
| 51 | + customers:create_index('index5_dropped', { |
| 52 | + type = 'HASH', |
| 53 | + parts = {'age'}, |
| 54 | + if_not_exists = true, |
| 55 | + }) |
| 56 | + |
| 57 | + customers:create_index('index6', { |
| 58 | + type = 'TREE', |
| 59 | + parts = {'name'}, |
| 60 | + unique = false, |
| 61 | + if_not_exists = true, |
| 62 | + }) |
| 63 | + |
| 64 | + customers.index.index4_dropped:drop() |
| 65 | + customers.index.index5_dropped:drop() |
| 66 | + |
| 67 | + -- We need this check to make sure that test actually covers a problem. |
| 68 | + t.assert(#box.space.customers.index ~= table.maxn(box.space.customers.index)) |
| 69 | +end |
| 70 | + |
| 71 | +g.after_all = function() |
| 72 | + box.space.customers:drop() |
| 73 | +end |
| 74 | + |
| 75 | +g.test_before_dropped_index_field = function() |
| 76 | + local conditions = { cond_funcs.eq('index3', 20) } |
| 77 | + local plan, err = select_plan.new(box.space.customers, conditions) |
| 78 | + |
| 79 | + t.assert_equals(err, nil) |
| 80 | + t.assert_type(plan, 'table') |
| 81 | + |
| 82 | + t.assert_equals(plan.conditions, conditions) |
| 83 | + t.assert_equals(plan.space_name, 'customers') |
| 84 | + t.assert_equals(plan.index_id, 2) |
| 85 | +end |
| 86 | + |
| 87 | +g.test_after_dropped_index_field = function() |
| 88 | + local conditions = { cond_funcs.eq('index6', 'Alexey') } |
| 89 | + local plan, err = select_plan.new(box.space.customers, conditions) |
| 90 | + |
| 91 | + t.assert_equals(err, nil) |
| 92 | + t.assert_type(plan, 'table') |
| 93 | + |
| 94 | + t.assert_equals(plan.conditions, conditions) |
| 95 | + t.assert_equals(plan.space_name, 'customers') |
| 96 | + t.assert_equals(plan.index_id, 5) |
| 97 | +end |
| 98 | + |
| 99 | +g.test_non_indexed_field = function() |
| 100 | + local conditions = { cond_funcs.eq('number_of_pets', 2) } |
| 101 | + local plan, err = select_plan.new(box.space.customers, conditions) |
| 102 | + |
| 103 | + t.assert_equals(err, nil) |
| 104 | + t.assert_type(plan, 'table') |
| 105 | + |
| 106 | + t.assert_equals(plan.conditions, conditions) |
| 107 | + t.assert_equals(plan.space_name, 'customers') |
| 108 | + t.assert_equals(plan.index_id, 0) -- PK |
| 109 | +end |
0 commit comments