Skip to content

Commit 9d1ec25

Browse files
MDEV-40168 wip
1 parent ff09eef commit 9d1ec25

18 files changed

Lines changed: 605 additions & 7 deletions

libmysqld/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
7272
../sql/mf_iocache.cc ../sql/my_decimal.cc
7373
../sql/net_serv.cc ../sql/opt_range.cc
7474
../sql/opt_group_by_cardinality.cc
75+
../sql/opt_multi_valued_index.cc
7576
../sql/opt_rewrite_date_cmp.cc
7677
../sql/opt_rewrite_remove_casefold.cc
7778
../sql/opt_sargable_left.cc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--innodb_ft_index_cache
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# basic test
2+
SET SESSION debug = '+d,test_invisible_index,test_completely_invisible';
3+
create table t1 (c int, j json, key idx ((CAST(j->'$.tags' AS CHAR(6) ARRAY))))engine=innodb;
4+
SHOW CREATE TABLE t1;
5+
Table Create Table
6+
t1 CREATE TABLE `t1` (
7+
`c` int(11) DEFAULT NULL,
8+
`j` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`j`))
9+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
10+
show index from t1;
11+
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
12+
t1 1 invisible1 1 invisible1 A 0 NULL NULL YES BTREE NO
13+
t1 1 idx 1 DB_MVI_1 NULL NULL NULL NULL YES FULLTEXT NO
14+
set @old_innodb_ft_aux_table=@@global.innodb_ft_aux_table;
15+
set global innodb_ft_aux_table='test/t1';
16+
insert into t1 values (1, '{"tags": [1, "abcde", "34567", "", 34567]}');
17+
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE;
18+
WORD FIRST_DOC_ID LAST_DOC_ID DOC_COUNT DOC_ID POSITION
19+
31xx 1 1 1 1 0
20+
3334353637 1 1 1 1 16
21+
3334353637 1 1 1 1 16
22+
6162636465 1 1 1 1 5
23+
xxxx 1 1 1 1 27
24+
select json_contains(j->'$.tags', '"abcde"') from t1;
25+
json_contains(j->'$.tags', '"abcde"')
26+
1
27+
explain
28+
select * from t1 where json_contains(j->'$.tags', '"abcde"');
29+
id select_type table type possible_keys key key_len ref rows Extra
30+
1 SIMPLE t1 fulltext idx idx 0 1 Using where
31+
select * from t1 where json_contains(j->'$.tags', '"abcde"');
32+
c j
33+
1 {"tags": [1, "abcde", "34567", "", 34567]}
34+
DROP TABLE t1;
35+
set global innodb_ft_aux_table=@old_innodb_ft_aux_table;
36+
# direct call of mvi_encode
37+
select mvi_encode('[1, 42, "3"]', int);
38+
mvi_encode('[1, 42, "3"]', int)
39+
8000000000000001 800000000000002a 8000000000000003
40+
select mvi_encode('[1, 42, "3"]', unsigned);
41+
mvi_encode('[1, 42, "3"]', unsigned)
42+
0000000000000001 000000000000002a 0000000000000003
43+
select mvi_encode('[1, 42, "3 "]', char(6));
44+
mvi_encode('[1, 42, "3 "]', char(6))
45+
31xx 3432 33xx
46+
select mvi_encode('[1, 42, " "]', char(6));
47+
mvi_encode('[1, 42, " "]', char(6))
48+
31xx 3432 xxxx
49+
select mvi_encode('[1, 42, "3 "]', binary(6));
50+
mvi_encode('[1, 42, "3 "]', binary(6))
51+
31xx 3432 33xx
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--source include/have_innodb.inc
2+
3+
--echo # basic test
4+
SET SESSION debug = '+d,test_invisible_index,test_completely_invisible';
5+
6+
create table t1 (c int, j json, key idx ((CAST(j->'$.tags' AS CHAR(6) ARRAY))))engine=innodb;
7+
SHOW CREATE TABLE t1;
8+
show index from t1;
9+
10+
set @old_innodb_ft_aux_table=@@global.innodb_ft_aux_table;
11+
set global innodb_ft_aux_table='test/t1';
12+
13+
insert into t1 values (1, '{"tags": [1, "abcde", "34567", "", 34567]}');
14+
15+
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE;
16+
17+
select json_contains(j->'$.tags', '"abcde"') from t1;
18+
explain
19+
select * from t1 where json_contains(j->'$.tags', '"abcde"');
20+
select * from t1 where json_contains(j->'$.tags', '"abcde"');
21+
22+
DROP TABLE t1;
23+
24+
set global innodb_ft_aux_table=@old_innodb_ft_aux_table;
25+
26+
--echo # direct call of mvi_encode
27+
select mvi_encode('[1, 42, "3"]', int);
28+
select mvi_encode('[1, 42, "3"]', unsigned);
29+
select mvi_encode('[1, 42, "3 "]', char(6));
30+
select mvi_encode('[1, 42, " "]', char(6));
31+
select mvi_encode('[1, 42, "3 "]', binary(6));

sql/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ SET (SQL_SOURCE
122122
opt_rewrite_remove_casefold.cc
123123
opt_sargable_left.cc
124124
opt_sum.cc
125-
opt_vcol_substitution.cc
126125
../sql-common/pack.c parse_file.cc password.c procedure.cc
127126
protocol.cc records.cc repl_failsafe.cc rpl_filter.cc
128127
session_tracker.cc
@@ -199,6 +198,8 @@ SET (SQL_SOURCE
199198
json_table.cc
200199
proxy_protocol.cc backup.cc xa.cc
201200
socketpair.c socketpair.h
201+
opt_multi_valued_index.h
202+
opt_multi_valued_index.cc
202203
opt_vcol_substitution.h
203204
opt_vcol_substitution.cc
204205
opt_hints_parser.cc opt_hints_parser.h scan_char.h

sql/item.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,6 +2473,11 @@ class Item :public Value_source,
24732473
*/
24742474
virtual bool check_index_dependence(void *arg) { return 0; }
24752475
virtual bool check_sequence_privileges(void *arg) { return 0; }
2476+
/*
2477+
Find sargable MVI conditions, create the corresponding
2478+
Item_func_match condition, then AND them to the original
2479+
*/
2480+
virtual bool mvi_ft_processor(void *arg) { return 0; }
24762481
/*============== End of Item processor list ======================*/
24772482

24782483
/*
@@ -2859,6 +2864,11 @@ class Item :public Value_source,
28592864
DBUG_ASSERT(fixed());
28602865
return false;
28612866
}
2867+
virtual Item *create_ft_for_mvi(THD *thd, List<Field> *vcol_fields)
2868+
{
2869+
return NULL;
2870+
}
2871+
28622872

28632873
protected:
28642874
/*

sql/item_func.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ class Item_func :public Item_func_or_sum
109109
JSON_EXTRACT_FUNC, JSON_VALID_FUNC, ROWNUM_FUNC,
110110
CASE_SEARCHED_FUNC, // Used by ColumnStore/Spider
111111
CASE_SIMPLE_FUNC, // Used by ColumnStore/spider,
112-
DATE_FUNC, YEAR_FUNC, SUBSTR_FUNC, LEFT_FUNC
112+
DATE_FUNC, YEAR_FUNC, SUBSTR_FUNC, LEFT_FUNC,
113+
MVI_ENCODE_FUNC
113114
};
114115

115116
/*

sql/item_jsonfunc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ class Item_func_json_contains: public Item_bool_func
376376
}
377377
bool fix_length_and_dec(THD *thd) override;
378378
bool val_bool() override;
379+
Item *create_ft_for_mvi(THD *thd, List<Field> *vcol_fields) override;
379380

380381
protected:
381382
Item *shallow_copy(THD *thd) const override

sql/item_strfunc.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,6 +2643,30 @@ class Item_temptable_rowid :public Item_str_func
26432643
{ return get_item_copy<Item_temptable_rowid>(thd, this); }
26442644
};
26452645

2646+
class Item_func_mvi_encode : public Item_str_ascii_func
2647+
{
2648+
Lex_cast_type_st m_cast_type;
2649+
String tmp_js;
2650+
json_engine_t je;
2651+
public:
2652+
void print(String *str, enum_query_type query_type) override;
2653+
Item_func_mvi_encode(THD* thd, Item *expr, const Lex_cast_type_st &cast_type):
2654+
Item_str_ascii_func(thd, expr), m_cast_type(cast_type) {}
2655+
String *val_str_ascii(String *buf) override;
2656+
enum Functype functype() const override { return MVI_ENCODE_FUNC; }
2657+
LEX_CSTRING func_name_cstring() const override
2658+
{
2659+
static LEX_CSTRING name= {STRING_WITH_LEN("mvi_encode")};
2660+
return name;
2661+
}
2662+
bool fix_length_and_dec(THD *thd) override;
2663+
Item *shallow_copy(THD *thd) const override
2664+
{
2665+
return get_item_copy<Item_func_mvi_encode>(thd, this);
2666+
}
2667+
Lex_cast_type_st &cast_type() { return m_cast_type; }
2668+
};
2669+
26462670

26472671
class Item_func_format_pico_time : public Item_str_ascii_func
26482672
{

sql/lex.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ SYMBOL symbols[] = {
419419
{ "MONITOR", SYM(MONITOR_SYM)},
420420
{ "MONTH", SYM(MONTH_SYM)},
421421
{ "MUTEX", SYM(MUTEX_SYM)},
422+
{ "MVI_ENCODE", SYM(MVI_ENCODE_SYM)},
422423
{ "MYSQL", SYM(MYSQL_SYM)},
423424
{ "MYSQL_ERRNO", SYM(MYSQL_ERRNO_SYM)},
424425
{ "NAME", SYM(NAME_SYM)},

0 commit comments

Comments
 (0)