Commit 2d1e09a7 authored by Yuchen Pei's avatar Yuchen Pei

MDEV-26247 Clean up spider_fields

Spider gbh query rewrite should get table for fields in a simple way.
Add a method spider_fields::find_table that searches its table holders
to find table for a given field. This way we will be able to get rid
of the first pass during the gbh creation where field_chains and
field_holders are created.

We also check that the field belongs to a spider table while walking
through the query, so we could remove
all_query_fields_are_query_table_members(). However, this requires an
earlier creation of the table_holder so that tables are added before
checking. We do that, and in doing so, also decouple table_holder and
spider_fields

Remove unused methods and fields. Add comments.
parent 8c1dcb25
...@@ -9167,19 +9167,20 @@ int spider_db_open_item_ident( ...@@ -9167,19 +9167,20 @@ int spider_db_open_item_ident(
} else { } else {
if (str) if (str)
{ {
SPIDER_FIELD_CHAIN *field_chain = fields->get_next_field_chain(); SPIDER_TABLE_HOLDER *table= fields->find_table(field);
SPIDER_FIELD_HOLDER *field_holder = field_chain->field_holder; /* If table or table->spider is NULL the GBH creation
spider = field_holder->spider; would have been skipped the first pass (see below). */
spider = table->spider;
share = spider->share; share = spider->share;
if ((error_num = share->dbton_share[dbton_id]-> if ((error_num = share->dbton_share[dbton_id]->
append_column_name_with_alias(str, field->field_index, append_column_name_with_alias(str, field->field_index,
field_holder->alias->ptr(), field_holder->alias->length()))) table->alias->ptr(), table->alias->length())))
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
} else { } else
if ((error_num = fields->add_field(field)))
{ {
DBUG_RETURN(error_num); SPIDER_TABLE_HOLDER *table= fields->find_table(field);
} if (!table || !table->spider)
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
} }
} }
} }
...@@ -9298,21 +9299,20 @@ int spider_db_open_item_field( ...@@ -9298,21 +9299,20 @@ int spider_db_open_item_field(
} else { } else {
if (str) if (str)
{ {
SPIDER_FIELD_CHAIN *field_chain = fields->get_next_field_chain(); SPIDER_TABLE_HOLDER *table= fields->find_table(field);
SPIDER_FIELD_HOLDER *field_holder = field_chain->field_holder; /* If table or table->spider is NULL the GBH creation
spider = field_holder->spider; would have been skipped the first pass (see below). */
spider = table->spider;
share = spider->share; share = spider->share;
field = spider->field_exchange(field);
DBUG_ASSERT(field);
if ((error_num = share->dbton_share[dbton_id]-> if ((error_num = share->dbton_share[dbton_id]->
append_column_name_with_alias(str, field->field_index, append_column_name_with_alias(str, field->field_index,
field_holder->alias->ptr(), field_holder->alias->length()))) table->alias->ptr(), table->alias->length())))
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
} else { } else
if ((error_num = fields->add_field(field)))
{ {
DBUG_RETURN(error_num); SPIDER_TABLE_HOLDER *table= fields->find_table(field);
} if (!table || !table->spider)
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
} }
DBUG_RETURN(0); DBUG_RETURN(0);
} }
......
...@@ -604,34 +604,26 @@ typedef struct spider_conn_holder ...@@ -604,34 +604,26 @@ typedef struct spider_conn_holder
spider_conn_holder *next; spider_conn_holder *next;
} SPIDER_CONN_HOLDER; } SPIDER_CONN_HOLDER;
/* Record information of a local (spider) table, for use of the spider
group by handler. */
typedef struct spider_table_holder typedef struct spider_table_holder
{ {
TABLE *table; TABLE *table;
ha_spider *spider; ha_spider *spider;
/* alias of the table, in the form of tk, where k is the index of
the table from `query->from' indexed by next_local. */
spider_string *alias; spider_string *alias;
} SPIDER_TABLE_HOLDER; } SPIDER_TABLE_HOLDER;
typedef struct spider_field_holder /* For use of the spider group by handler. */
{
Field *field;
ha_spider *spider;
spider_string *alias;
spider_field_holder *next;
} SPIDER_FIELD_HOLDER;
typedef struct spider_field_chain
{
spider_field_holder *field_holder;
spider_field_chain *next;
} SPIDER_FIELD_CHAIN;
class spider_fields class spider_fields
{ {
uint dbton_count; uint dbton_count;
uint current_dbton_num; uint current_dbton_num;
uint dbton_ids[SPIDER_DBTON_SIZE]; uint dbton_ids[SPIDER_DBTON_SIZE];
/* Number of tables in `query->from'. */
uint table_count; uint table_count;
uint current_table_num; /* All tables in `query->from', in the same order by next_local. */
SPIDER_TABLE_HOLDER *table_holder; SPIDER_TABLE_HOLDER *table_holder;
SPIDER_LINK_IDX_CHAIN *first_link_idx_chain; SPIDER_LINK_IDX_CHAIN *first_link_idx_chain;
SPIDER_LINK_IDX_CHAIN *last_link_idx_chain; SPIDER_LINK_IDX_CHAIN *last_link_idx_chain;
...@@ -640,13 +632,6 @@ class spider_fields ...@@ -640,13 +632,6 @@ class spider_fields
SPIDER_CONN_HOLDER *first_conn_holder; SPIDER_CONN_HOLDER *first_conn_holder;
SPIDER_CONN_HOLDER *last_conn_holder; SPIDER_CONN_HOLDER *last_conn_holder;
SPIDER_CONN_HOLDER *current_conn_holder; SPIDER_CONN_HOLDER *current_conn_holder;
SPIDER_FIELD_HOLDER *first_field_holder;
SPIDER_FIELD_HOLDER *last_field_holder;
SPIDER_FIELD_HOLDER *current_field_holder;
SPIDER_FIELD_CHAIN *first_field_chain;
SPIDER_FIELD_CHAIN *last_field_chain;
SPIDER_FIELD_CHAIN *current_field_chain;
Field **first_field_ptr;
Field **current_field_ptr; Field **current_field_ptr;
public: public:
spider_fields(); spider_fields();
...@@ -702,24 +687,14 @@ class spider_fields ...@@ -702,24 +687,14 @@ class spider_fields
void free_conn_holder( void free_conn_holder(
SPIDER_CONN_HOLDER *conn_holder_arg SPIDER_CONN_HOLDER *conn_holder_arg
); );
SPIDER_TABLE_HOLDER *add_table( SPIDER_TABLE_HOLDER *find_table(Field *field);
ha_spider *spider_arg void set_table_holder(
); SPIDER_TABLE_HOLDER *table_holder_arg,
bool all_query_fields_are_query_table_members();
int create_table_holder(
uint table_count_arg uint table_count_arg
); );
void set_pos_to_first_table_holder(); SPIDER_TABLE_HOLDER *get_first_table_holder();
SPIDER_TABLE_HOLDER *get_next_table_holder();
SPIDER_TABLE_HOLDER *get_table_holder(TABLE *table); SPIDER_TABLE_HOLDER *get_table_holder(TABLE *table);
uint get_table_count(); uint get_table_count();
int add_field(Field *field_arg);
SPIDER_FIELD_HOLDER *create_field_holder();
void set_pos_to_first_field_holder();
SPIDER_FIELD_HOLDER *get_next_field_holder();
SPIDER_FIELD_CHAIN *create_field_chain();
void set_pos_to_first_field_chain();
SPIDER_FIELD_CHAIN *get_next_field_chain();
void set_field_ptr(Field **field_arg); void set_field_ptr(Field **field_arg);
Field **get_next_field_ptr(); Field **get_next_field_ptr();
int ping_table_mon_from_table( int ping_table_mon_from_table(
......
...@@ -15639,8 +15639,7 @@ int spider_mbase_handler::append_from_and_tables_part( ...@@ -15639,8 +15639,7 @@ int spider_mbase_handler::append_from_and_tables_part(
default: default:
DBUG_RETURN(0); DBUG_RETURN(0);
} }
fields->set_pos_to_first_table_holder(); table_holder = fields->get_first_table_holder();
table_holder = fields->get_next_table_holder();
table_list = table_holder->table->pos_in_table_list; table_list = table_holder->table->pos_in_table_list;
error_num = spider_db_mbase_utility->append_from_and_tables( error_num = spider_db_mbase_utility->append_from_and_tables(
table_holder->spider, fields, str, table_holder->spider, fields, str,
......
...@@ -676,8 +676,11 @@ class spider_mbase_share: public spider_db_share ...@@ -676,8 +676,11 @@ class spider_mbase_share: public spider_db_share
spider_string *show_table_status; spider_string *show_table_status;
spider_string *show_records; spider_string *show_records;
spider_string *show_index; spider_string *show_index;
/* The remote table names */
spider_string *table_names_str; spider_string *table_names_str;
/* The remote db names */
spider_string *db_names_str; spider_string *db_names_str;
/* fixme: this field looks useless */
spider_string *db_table_str; spider_string *db_table_str;
#ifdef SPIDER_HAS_HASH_VALUE_TYPE #ifdef SPIDER_HAS_HASH_VALUE_TYPE
my_hash_value_type *db_table_str_hash_value; my_hash_value_type *db_table_str_hash_value;
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment