@@ -7481,6 +7481,7 @@ int ha_partition::ft_read(uchar *buf)
74817481 DBUG_RETURN (result);
74827482}
74837483
7484+
74847485/*
74857486 Returns true if for a PARTITION BY RANGE table there is no need for
74867487 priority queue for index scan. In this case an unordered index scan
@@ -7494,24 +7495,34 @@ int ha_partition::ft_read(uchar *buf)
74947495 , OR
74957496
74967497 Case 2. The PARTITION BY RANGE expression is col1 and the active
7497- index is (prefix_cols, col1, ...), and we are in
7498- index_read_map(prefix_cols=prefix_value), or
7499- read_range_first(start_key= {prefix_value, ...},
7500- end_key={prefix_value, ...}), or
7501- multi_range_read_next(start_key= {prefix_value, ...},
7502- end_key={prefix_value, ...})
7498+ index is (prefix_cols, col1, ...), and we are in one of
7499+ * index_read_map(prefix_cols=prefix_value)
7500+ * read_range_first(start_key= {prefix_value, ...},
7501+ end_key= {prefix_value, ...})
7502+ * multi_range_read_next(start_key= {prefix_value, ...},
7503+ end_key= {prefix_value, ...})
75037504*/
7505+
75047506bool ha_partition::can_skip_merging_scans ()
75057507{
75067508 Field *part_field= NULL ;
75077509 uint i;
75087510 m_unordered_prefix_len= 0 ;
7511+
75097512 if (m_index_scan_type != partition_index_first &&
75107513 m_index_scan_type != partition_index_last &&
75117514 m_index_scan_type != partition_index_read &&
75127515 m_index_scan_type != partition_read_range &&
75137516 m_index_scan_type != partition_read_multi_range)
7517+ {
7518+ /*
7519+ This is partition_ft_read or partition_no_index_scan. We shouldn't
7520+ get here.
7521+ */
7522+ DBUG_ASSERT (0 );
75147523 return false ;
7524+ }
7525+
75157526 if (m_part_info->part_type != RANGE_PARTITION || m_is_sub_partitioned)
75167527 return false ;
75177528 if (m_part_info->part_expr &&
@@ -7525,13 +7536,15 @@ bool ha_partition::can_skip_merging_scans()
75257536 KEY_PART_INFO *key_part= &m_curr_key_info[0 ]->key_part [i];
75267537 if (key_part->field != part_field)
75277538 break ;
7539+
7540+ /* Currently, we disallow indexes with mixed ASC and DESC key parts: */
7541+ bool kp_is_reverse= MY_TEST (key_part->key_part_flag & HA_REVERSE_SORT);
75287542 if (i == 0 )
7529- m_unordered_reverse_index=
7530- (key_part->key_part_flag & HA_REVERSE_SORT) ? true : false ;
7531- else if (m_unordered_reverse_index !=
7532- ((key_part->key_part_flag & HA_REVERSE_SORT) ? true : false ))
7533- return false ; /* TODO: support mixed ASC/DESC keys */
7543+ m_unordered_reverse_index= kp_is_reverse;
7544+ else if (m_unordered_reverse_index != kp_is_reverse)
7545+ return false ;
75347546 }
7547+
75357548 /* Case 1 */
75367549 /*
75377550 We read to the empty partition field, so the partition columns are
@@ -7560,21 +7573,27 @@ bool ha_partition::can_skip_merging_scans()
75607573 m_unordered_reverse_index=
75617574 (key_part->key_part_flag & HA_REVERSE_SORT) ? true : false ;
75627575 if (m_index_scan_type == partition_index_read)
7576+ {
75637577 return
75647578 m_start_key.key && (m_start_key.keypart_map & prefix) == prefix;
7579+ }
75657580 else if (m_index_scan_type == partition_read_range)
7581+ {
75667582 return
75677583 m_start_key.key && (m_start_key.keypart_map & prefix) == prefix &&
75687584 end_range && (end_range->keypart_map & prefix) == prefix &&
75697585 !memcmp (m_start_key.key , end_range->key , m_unordered_prefix_len);
7586+ }
75707587 else /* (m_index_scan_type == partition_read_multi_range) */
7588+ {
75717589 return
75727590 (m_mrr_range_current->key_multi_range .start_key .keypart_map &
75737591 prefix) == prefix &&
75747592 (m_mrr_range_current->key_multi_range .end_key .keypart_map &
75757593 prefix) == prefix &&
75767594 !memcmp (m_mrr_range_current->key [0 ], m_mrr_range_current->key [1 ],
75777595 m_unordered_prefix_len);
7596+ }
75787597 }
75797598 }
75807599 return false ;
0 commit comments