@@ -38,6 +38,7 @@ Created 9/17/2000 Heikki Tuuri
38
38
#include " btr0sea.h"
39
39
#include " dict0boot.h"
40
40
#include " dict0crea.h"
41
+ #include < sql_const.h>
41
42
#include " dict0dict.h"
42
43
#include " dict0load.h"
43
44
#include " dict0stats.h"
@@ -804,8 +805,10 @@ row_create_prebuilt(
804
805
row_prebuilt_t * prebuilt;
805
806
mem_heap_t * heap;
806
807
dict_index_t * clust_index;
808
+ dict_index_t * temp_index;
807
809
dtuple_t * ref;
808
810
ulint ref_len;
811
+ uint srch_key_len = 0 ;
809
812
ulint search_tuple_n_fields;
810
813
811
814
search_tuple_n_fields = 2 * dict_table_get_n_cols (table);
@@ -817,6 +820,14 @@ row_create_prebuilt(
817
820
818
821
ref_len = dict_index_get_n_unique (clust_index);
819
822
823
+
824
+ /* Maximum size of the buffer needed for conversion of INTs from
825
+ little endian format to big endian format in an index. An index
826
+ can have maximum 16 columns (MAX_REF_PARTS) in it. Therfore
827
+ Max size for PK: 16 * 8 bytes (BIGINT's size) = 128 bytes
828
+ Max size Secondary index: 16 * 8 bytes + PK = 256 bytes. */
829
+ #define MAX_SRCH_KEY_VAL_BUFFER 2 * (8 * MAX_REF_PARTS)
830
+
820
831
#define PREBUILT_HEAP_INITIAL_SIZE \
821
832
( \
822
833
sizeof (*prebuilt) \
@@ -845,10 +856,38 @@ row_create_prebuilt(
845
856
+ sizeof (que_thr_t ) \
846
857
)
847
858
859
+ /* Calculate size of key buffer used to store search key in
860
+ InnoDB format. MySQL stores INTs in little endian format and
861
+ InnoDB stores INTs in big endian format with the sign bit
862
+ flipped. All other field types are stored/compared the same
863
+ in MySQL and InnoDB, so we must create a buffer containing
864
+ the INT key parts in InnoDB format.We need two such buffers
865
+ since both start and end keys are used in records_in_range(). */
866
+
867
+ for (temp_index = dict_table_get_first_index (table); temp_index;
868
+ temp_index = dict_table_get_next_index (temp_index)) {
869
+ DBUG_EXECUTE_IF (" innodb_srch_key_buffer_max_value" ,
870
+ ut_a (temp_index->n_user_defined_cols
871
+ == MAX_REF_PARTS););
872
+ uint temp_len = 0 ;
873
+ for (int i = 0 ; i < temp_index->n_uniq ; i++) {
874
+ if (temp_index->fields [i].col ->mtype == DATA_INT) {
875
+ temp_len +=
876
+ temp_index->fields [i].fixed_len ;
877
+ }
878
+ }
879
+ srch_key_len = std::max (srch_key_len,temp_len);
880
+ }
881
+
882
+ ut_a (srch_key_len <= MAX_SRCH_KEY_VAL_BUFFER);
883
+
884
+ DBUG_EXECUTE_IF (" innodb_srch_key_buffer_max_value" ,
885
+ ut_a (srch_key_len == MAX_SRCH_KEY_VAL_BUFFER););
886
+
848
887
/* We allocate enough space for the objects that are likely to
849
888
be created later in order to minimize the number of malloc()
850
889
calls */
851
- heap = mem_heap_create (PREBUILT_HEAP_INITIAL_SIZE);
890
+ heap = mem_heap_create (PREBUILT_HEAP_INITIAL_SIZE + 2 * srch_key_len );
852
891
853
892
prebuilt = static_cast <row_prebuilt_t *>(
854
893
mem_heap_zalloc (heap, sizeof (*prebuilt)));
@@ -861,6 +900,18 @@ row_create_prebuilt(
861
900
prebuilt->sql_stat_start = TRUE ;
862
901
prebuilt->heap = heap;
863
902
903
+ prebuilt->srch_key_val_len = srch_key_len;
904
+ if (prebuilt->srch_key_val_len ) {
905
+ prebuilt->srch_key_val1 = static_cast <byte*>(
906
+ mem_heap_alloc (prebuilt->heap ,
907
+ 2 * prebuilt->srch_key_val_len ));
908
+ prebuilt->srch_key_val2 = prebuilt->srch_key_val1 +
909
+ prebuilt->srch_key_val_len ;
910
+ } else {
911
+ prebuilt->srch_key_val1 = NULL ;
912
+ prebuilt->srch_key_val2 = NULL ;
913
+ }
914
+
864
915
btr_pcur_reset (&prebuilt->pcur );
865
916
btr_pcur_reset (&prebuilt->clust_pcur );
866
917
0 commit comments