Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DocStore] Support range optimizations for JOINs for document indexes…
… and more Summary: (1) This diff introduces range optimizations support for JOINs for document indexes. (2) This diff also introduces a change that a new document will be created and the document path will be built for a null column for partial update if argument CHECK_EXISTS is not specified, i.e., the argument is CHECK_NONE or CHECK_NOTEXISTS. Before this diff, a null column doesn't support partial update. (3) This diff also fixes some issues with document keys with string type. Before this diff, the raw key data (with an extra byte for null) is store in InnoDB b-tree indexes. Now a 2-byte key length is stored before the key data (after the byte for null). Please note that document columns and their keys are always nullable. For example, a key "abc" will be stored as 6 bytes: 0x00 0x03 0x00 0x61 0x62 0x63, in which: the 1st byte indicates that this key is not null, the 2nd and 3rd bytes are the key length 3 in little endian format, the rest 3 bytes are the key data "abc". In InnoDB, the index type for string document keys now is DATA_BLOB instead of DATA_BINARY, also in MySQL, Field_varstring instead of Field_string instances will be created for string document keys so that the 2-byte length can be added. Examples of query plans with document indexes: Covering indexes: explain extended select a1 from t1 use document keys where doc11.int > 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range doc11_int doc11_int 9 NULL 7 100.00 Using where; Using index Non-covering indexes: explain extended select doc11.string, doc11.int from t1 use document keys where doc11.string >= 'kkk'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range doc11_string doc11_string 103 NULL 1 100.00 Using where Covering indexes: explain extended select a1, doc11.int from t1 use document keys where doc11.int between 5 and 9; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range doc11_int doc11_int 9 NULL 5 100.00 Using where; Using index Covering indexes: explain extended select a1, doc11.int from t1 use document keys where doc11.int not in (5, 7, 9, 12); id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range doc11_int doc11_int 9 NULL 7 100.00 Using where; Using index Covering indexes: explain extended select t1.doc11.double, t2.doc21.double from t1 use document keys, t2 use document keys where t1.doc11.double > t2.doc21.double and t2.doc21.double > 10.1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 range doc21_double doc21_double 9 NULL 2 100.00 Using where; Using index 1 SIMPLE t1 ALL doc11_double NULL NULL NULL 12 100.00 Range checked for each record (index map: 0x10) Covering indexes: explain extended select t1.doc11.int, t2.doc21.int from t1 use document keys, t2 use document keys where (t1.doc11.int between 3 and 8) and (t2.doc21.int between 7 and 9) and t1.doc11.int > t2.doc21.int; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 range doc21_int doc21_int 9 NULL 3 100.00 Using where; Using index 1 SIMPLE t1 range doc11_int doc11_int 9 NULL 6 100.00 Using where; Using index; Using join buffer (Block Nested Loop) Non-covering indexes: explain extended select t1.doc11.int, t1.doc11.string, t2.doc21.int, t2.doc21.string from t1 use document keys, t2 use document keys where (t1.doc11.int between 3 and 8) and (t2.doc21.int between 7 and 9) and t1.doc11.int > t2.doc21.int; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 range doc21_int doc21_int 9 NULL 3 100.00 Using where 1 SIMPLE t1 ALL doc11_int NULL NULL NULL 12 50.00 Using where; Using join buffer (Block Nested Loop) Covering indexes: explain extended select t1.doc11.int, t2.doc21.int, t3.doc31.int from t1 use document keys, t2 use document keys, t3 use document keys where t1.doc11.int = t2.doc21.int and t1.doc11.int = t3.doc31.int; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index doc11_int doc11_int 9 NULL 12 100.00 Using where; Using index 1 SIMPLE t2 ref doc21_int doc21_int 9 test.t1.`doc11`.`int` 1 100.00 Using index 1 SIMPLE t3 ref doc31_int doc31_int 9 test.t1.`doc11`.`int` 1 100.00 Using index Covering indexes: explain extended select t1.doc11.int, t2.doc21.int, t3.doc31.int from t1 use document keys, t2 use document keys, t3 use document keys where t1.doc11.int > t2.doc21.int and t2.doc21.int > t3.doc31.int and t3.doc31.int > 10; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t3 range doc31_int doc31_int 9 NULL 2 100.00 Using where; Using index 1 SIMPLE t1 index doc11_int doc11_int 9 NULL 12 100.00 Using index; Using join buffer (Block Nested Loop) 1 SIMPLE t2 ALL doc21_int NULL NULL NULL 12 100.00 Range checked for each record (index map: 0x8) Covering indexes: explain extended select t1.doc11.int, t2.doc21.int, t3.doc31.int from t1 use document keys, t2 use document keys, t3 use document keys where (t1.doc11.int between 3 and 8) and (t2.doc21.int between 7 and 9) and (t3.doc31.int between 6 and 10) and (t1.doc11.int > t2.doc21.int and t2.doc21.int > t3.doc31.int); id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 range doc21_int doc21_int 9 NULL 3 100.00 Using where; Using index 1 SIMPLE t3 range doc31_int doc31_int 9 NULL 5 100.00 Using where; Using index; Using join buffer (Block Nested Loop) 1 SIMPLE t1 range doc11_int doc11_int 9 NULL 6 100.00 Using where; Using index; Using join buffer (Block Nested Loop) Non-covering indexes: explain extended select t1.doc11.int, t1.doc11.double, t2.doc21.int, t2.doc21.double, t3.doc31.int, t3.doc31.double from t1 use document keys, t2 use document keys, t3 use document keys where (t1.doc11.double between 3.3 and 8.8) and (t2.doc21.double between 7.7 and 9.9) and (t3.doc31.double between 6.6 and 10.1) and (t1.doc11.double > t2.doc21.double and t2.doc21.double > t3.doc31.double); id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 range doc21_double doc21_double 9 NULL 3 100.00 Using where 1 SIMPLE t3 ALL doc31_double NULL NULL NULL 12 41.67 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t1 ALL doc11_double NULL NULL NULL 12 50.00 Using where; Using join buffer (Block Nested Loop) Test Plan: MTR Reviewers: tianx Reviewed By: tianx Subscribers: webscalesql-eng Differential Revision: https://reviews.facebook.net/D50757 Differential Revision: https://reviews.facebook.net/D52497
- Loading branch information