Skip to content

Commit cce9019

Browse files
ShannonBaseRingsC
andauthored
merge develop to main (mysql#95)
to enable ART index . --------- Co-authored-by: RingsC <[email protected]>
1 parent 080d1fa commit cce9019

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2953
-646
lines changed

sql/handler.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4498,7 +4498,7 @@ class handler {
44984498
of the current range.
44994499
*/
45004500
enum enum_range_scan_direction { RANGE_SCAN_ASC, RANGE_SCAN_DESC };
4501-
4501+
int get_key_comp_result() { return key_compare_result_on_equal; }
45024502
private:
45034503
Record_buffer *m_record_buffer = nullptr; ///< Buffer for multi-row reads.
45044504
/*
@@ -4649,7 +4649,9 @@ class handler {
46494649
if (rc) end_psi_batch_mode();
46504650
return rc;
46514651
}
4652-
4652+
enum_range_scan_direction get_range_scan_direction() {
4653+
return range_scan_direction;
4654+
}
46534655
private:
46544656
/**
46554657
The lock type set by when calling::ha_external_lock(). This is

sql/sql_base.cc

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6680,21 +6680,63 @@ static bool open_secondary_engine_tables(THD *thd, uint flags) {
66806680
// The previous execution context should have been destroyed.
66816681
assert(lex->secondary_engine_execution_context() == nullptr);
66826682

6683+
// If use of primary engine is requested, set state accordingly
6684+
if (thd->variables.use_secondary_engine == SECONDARY_ENGINE_OFF) {
6685+
if (lex->can_execute_only_in_secondary_engine()) {
6686+
my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0),
6687+
lex->get_not_supported_in_primary_reason());
6688+
return true;
6689+
}
6690+
6691+
thd->set_secondary_engine_optimization(
6692+
Secondary_engine_optimization::PRIMARY_ONLY);
6693+
return false;
6694+
}
66836695
// If use of secondary engines has been disabled for the statement,
66846696
// there is nothing to do.
6685-
if (sql_cmd == nullptr || sql_cmd->secondary_storage_engine_disabled())
6697+
// Statements without Sql_cmd representations are for primary engine only:
6698+
if (sql_cmd == nullptr) {
6699+
thd->set_secondary_engine_optimization(
6700+
Secondary_engine_optimization::PRIMARY_ONLY);
66866701
return false;
6687-
6702+
}
6703+
/*
6704+
Only some SQL commands can be offloaded to secondary table offload.
6705+
Note that table-less queries are always executed in primary engine.
6706+
*/
6707+
const bool offload_possible =
6708+
(lex->sql_command == SQLCOM_SELECT && lex->table_count > 0) ||
6709+
((lex->sql_command == SQLCOM_INSERT_SELECT ||
6710+
lex->sql_command == SQLCOM_CREATE_TABLE) &&
6711+
lex->table_count > 1);
6712+
/*
6713+
If query can only execute in secondary engine, effectively set it as
6714+
a forced secondary execution.
6715+
*/
6716+
if (lex->can_execute_only_in_secondary_engine()) {
6717+
thd->set_secondary_engine_forced(true);
6718+
}
66886719
// If the user has requested the use of a secondary storage engine
66896720
// for this statement, skip past the initial optimization for the
66906721
// primary storage engine and go straight to the secondary engine.
66916722
if (thd->secondary_engine_optimization() ==
66926723
Secondary_engine_optimization::PRIMARY_TENTATIVELY &&
66936724
thd->variables.use_secondary_engine == SECONDARY_ENGINE_FORCED) {
6694-
thd->set_secondary_engine_optimization(
6695-
Secondary_engine_optimization::SECONDARY);
6696-
mysql_thread_set_secondary_engine(true);
6697-
mysql_statement_set_secondary_engine(thd->m_statement_psi, true);
6725+
if (offload_possible) {
6726+
thd->set_secondary_engine_optimization(
6727+
Secondary_engine_optimization::SECONDARY);
6728+
mysql_thread_set_secondary_engine(true);
6729+
mysql_statement_set_secondary_engine(thd->m_statement_psi, true);
6730+
} else {
6731+
// Table-less queries cannot be executed in secondary engine
6732+
if (lex->can_execute_only_in_secondary_engine()) {
6733+
my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0),
6734+
lex->get_not_supported_in_primary_reason());
6735+
return true;
6736+
}
6737+
thd->set_secondary_engine_optimization(
6738+
Secondary_engine_optimization::PRIMARY_ONLY);
6739+
}
66986740
}
66996741

67006742
// Only open secondary engine tables if use of a secondary engine

sql/sql_class.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4630,6 +4630,12 @@ class THD : public MDL_context_owner,
46304630
*/
46314631
bool is_secondary_storage_engine_eligible() const;
46324632

4633+
/// Indicate whether secondary storage engine is forced for this execution
4634+
void set_secondary_engine_forced(bool forced) {
4635+
m_secondary_engine_forced = forced;
4636+
}
4637+
4638+
bool is_secondary_engine_forced() const { return m_secondary_engine_forced; }
46334639
private:
46344640
/**
46354641
This flag tells if a secondary storage engine can be used to
@@ -4638,6 +4644,13 @@ class THD : public MDL_context_owner,
46384644
Secondary_engine_optimization m_secondary_engine_optimization =
46394645
Secondary_engine_optimization::PRIMARY_ONLY;
46404646

4647+
/**
4648+
Flag that tells whether secondary storage engine is forced for execution.
4649+
Notice that use_secondary_engine is not reliable because it may be restored
4650+
early.
4651+
*/
4652+
bool m_secondary_engine_forced{false};
4653+
46414654
void cleanup_after_parse_error();
46424655
/**
46434656
Flag that indicates if the user of current session has SYSTEM_USER privilege

sql/sql_lex.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3663,6 +3663,12 @@ class LEX_GRANT_AS {
36633663
List<LEX_USER> *role_list;
36643664
};
36653665

3666+
/*
3667+
Some queries can be executed only using the secondary engine. The enum
3668+
"execute_only_in_secondary_reasons" retains the explanations for queries that
3669+
cannot be executed using the primary engine.
3670+
*/
3671+
enum execute_only_in_secondary_reasons { SUPPORTED_IN_PRIMARY, CUBE };
36663672
/**
36673673
The LEX object currently serves three different purposes:
36683674
@@ -3726,6 +3732,9 @@ struct LEX : public Query_tables_list {
37263732
/* current Query_block in parsing */
37273733
Query_block *m_current_query_block;
37283734

3735+
bool m_can_execute_only_in_secondary_engine = false;
3736+
execute_only_in_secondary_reasons m_execute_only_in_secondary_engine_reason{
3737+
SUPPORTED_IN_PRIMARY};
37293738
public:
37303739
inline Query_block *current_query_block() const {
37313740
return m_current_query_block;
@@ -3848,7 +3857,28 @@ struct LEX : public Query_tables_list {
38483857
std::map<Item_field *, Field *>::iterator end_values_map() {
38493858
return insert_update_values_map->end();
38503859
}
3860+
bool can_execute_only_in_secondary_engine() const {
3861+
return m_can_execute_only_in_secondary_engine;
3862+
}
3863+
void set_execute_only_in_secondary_engine(
3864+
const bool execute_only_in_secondary_engine_param,
3865+
execute_only_in_secondary_reasons reason) {
3866+
m_can_execute_only_in_secondary_engine =
3867+
execute_only_in_secondary_engine_param;
3868+
m_execute_only_in_secondary_engine_reason = reason;
3869+
assert(m_can_execute_only_in_secondary_engine ||
3870+
reason == SUPPORTED_IN_PRIMARY);
3871+
}
38513872

3873+
const char *get_not_supported_in_primary_reason() {
3874+
assert(can_execute_only_in_secondary_engine());
3875+
switch (m_execute_only_in_secondary_engine_reason) {
3876+
case CUBE:
3877+
return "CUBE";
3878+
default:
3879+
return "UNDEFINED";
3880+
}
3881+
}
38523882
private:
38533883
/*
38543884
With Visual Studio, an std::map will always allocate two small objects

sql/sql_table.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@
200200
#include "typelib.h"
201201

202202
#include "storage/rapid_engine/include/rapid_stats.h" //meta_rpd_columns_infos
203+
#include "storage/rapid_engine/imcs/imcs.h"
204+
#include "storage/rapid_engine/imcs/cu.h"
203205
namespace dd {
204206
class View;
205207
} // namespace dd
@@ -2732,10 +2734,16 @@ static bool secondary_engine_load_table(THD *thd, const TABLE &table) {
27322734
row_rpd_columns.table_id = static_cast<uint>(table.s->table_map_id.id());
27332735
row_rpd_columns.column_id = field_ptr->field_index();
27342736
strncpy(row_rpd_columns.column_name, field_ptr->field_name,
2735-
strlen(row_rpd_columns.column_name));
2737+
strlen(field_ptr->field_name));
27362738
strncpy(row_rpd_columns.table_name, table.s->table_name.str,
2737-
strlen(row_rpd_columns.table_name));
2738-
row_rpd_columns.data_dict_bytes = 0;
2739+
strlen(table.s->table_name.str));
2740+
std::string key_name (table.s->db.str);
2741+
key_name += table.s->table_name.str;
2742+
key_name += field_ptr->field_name;
2743+
ShannonBase::Compress::Dictionary* dict =
2744+
ShannonBase::Imcs::Imcs::get_instance()->get_cu(key_name)->get_header()->m_local_dict.get();
2745+
if (dict)
2746+
row_rpd_columns.data_dict_bytes = dict->content_size();
27392747
row_rpd_columns.data_placement_index = 0;
27402748

27412749
std::string comment (field_ptr->comment.str);

storage/innobase/handler/ha_innodb.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ class ha_innobase : public handler {
472472
bool check_if_incompatible_data(HA_CREATE_INFO *info,
473473
uint table_changes) override;
474474

475+
virtual dict_index_t *innobase_get_index(uint keynr);
475476
private:
476477
/** @name Multi Range Read interface
477478
@{ */
@@ -504,7 +505,6 @@ class ha_innobase : public handler {
504505
@return idx_cond if pushed; NULL if not pushed */
505506
Item *idx_cond_push(uint keyno, Item *idx_cond) override;
506507
/** @} */
507-
508508
private:
509509
void update_thd();
510510

@@ -555,9 +555,7 @@ class ha_innobase : public handler {
555555
void update_thd(THD *thd);
556556

557557
int general_fetch(uchar *buf, uint direction, uint match_mode);
558-
559-
virtual dict_index_t *innobase_get_index(uint keynr);
560-
558+
561559
/** Builds a 'template' to the m_prebuilt struct. The template is used in fast
562560
retrieval of just those column values MySQL needs in its processing.
563561
@param[in] whole_row true if access is needed to a whole row, false if

storage/perfschema/pfs_engine_table.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@
120120
#include "storage/perfschema/table_replication_applier_status_by_worker.h"
121121
#include "storage/perfschema/table_rpd_column_id.h" // rpd_column_id
122122
#include "storage/perfschema/table_rpd_columns.h" // rpd_columns
123+
#include "storage/perfschema/table_rpd_preload_stats.h" // rpd_preload_stats
124+
#include "storage/perfschema/table_rpd_table_id.h" // rpd_table_id
125+
#include "storage/perfschema/table_rpd_tables.h" // rpd_tables
123126
/* For replication related perfschema tables. */
124127
#include "storage/perfschema/table_log_status.h"
125128
#include "storage/perfschema/table_replication_asynchronous_connection_failover.h"
@@ -585,6 +588,10 @@ static PFS_engine_table_share *all_shares[] = {
585588
&table_rpl_async_connection_failover_managed::m_share,
586589
&table_rpd_column_id::m_share,
587590
&table_rpd_columns::m_share,
591+
&table_rpd_table_id::m_share,
592+
&table_rpd_tables::m_share,
593+
&table_rpd_preload_stats::m_share,
594+
588595
&table_log_status::m_share,
589596

590597
&table_prepared_stmt_instances::m_share,

storage/perfschema/table_rpd_column_id.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ int table_rpd_column_id::make_row(uint index[[maybe_unused]]) {
137137
} else {
138138
m_row.column_id = ShannonBase::meta_rpd_columns_infos[index].column_id;
139139
m_row.table_id = ShannonBase::meta_rpd_columns_infos[index].table_id;
140+
140141
strncpy(m_row.column_name, ShannonBase::meta_rpd_columns_infos[index].column_name,
141-
strlen(m_row.column_name));
142+
strlen(ShannonBase::meta_rpd_columns_infos[index].column_name));
142143
m_row.column_name_length = strlen(ShannonBase::meta_rpd_columns_infos[index].column_name);
143144
}
144145
return 0;

storage/perfschema/table_rpd_columns.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ int table_rpd_columns::make_row(uint index[[maybe_unused]]) {
149149
m_row.ndv = ShannonBase::meta_rpd_columns_infos[index].ndv;
150150
memset(m_row.encoding, 0x0, NAME_LEN);
151151
strncpy(m_row.encoding, ShannonBase::meta_rpd_columns_infos[index].encoding,
152-
strlen(m_row.encoding));
152+
strlen(ShannonBase::meta_rpd_columns_infos[index].encoding));
153153
}
154154
return 0;
155155
}

0 commit comments

Comments
 (0)