Skip to content

Commit d56f42a

Browse files
MDEV-37113 Some cleanup and documentation of spider gbh creation
1 parent eb337a2 commit d56f42a

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

storage/spider/ha_spider.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,17 @@ class ha_spider final : public handler
9595
bool da_status;
9696
bool use_spatial_index;
9797

98+
/*
99+
Index of the table in FROM tables, for the use of direct
100+
execution by gbh
101+
*/
98102
uint idx_for_direct_join;
103+
/*
104+
Whether using a spider_fields, only applicable to direct
105+
execution by gbh
106+
*/
99107
bool use_fields;
108+
/* If use_fields == true, the spider_fields in use for gbh */
100109
spider_fields *fields;
101110
SPIDER_LINK_IDX_CHAIN *link_idx_chain;
102111
SPIDER_LINK_IDX_CHAIN *result_link_idx_chain;

storage/spider/spd_db_include.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ class spider_fields
616616
);
617617
SPIDER_CONN_HOLDER *create_conn_holder();
618618
bool has_conn_holder();
619-
void clear_conn_holder_from_conn();
619+
void clear_conn_holder_checked();
620620
bool check_conn_same_conn(
621621
SPIDER_CONN *conn_arg
622622
);

storage/spider/spd_group_by_handler.cc

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,8 @@ bool spider_fields::has_conn_holder(
631631
DBUG_RETURN(first_conn_holder);
632632
}
633633

634-
void spider_fields::clear_conn_holder_from_conn(
634+
/* Mark checked_for_same_conn to false for all conn holders */
635+
void spider_fields::clear_conn_holder_checked(
635636
) {
636637
DBUG_ENTER("spider_fields::clear_conn_checked_for_same_conn");
637638
DBUG_PRINT("info",("spider this=%p", this));
@@ -643,6 +644,9 @@ void spider_fields::clear_conn_holder_from_conn(
643644
DBUG_VOID_RETURN;
644645
}
645646

647+
/* Set current conn holder to be the first conn holder with a matching
648+
conn and mark its checked_for_same_conn to be true. Return true if
649+
one is found and vice versa. */
646650
bool spider_fields::check_conn_same_conn(
647651
SPIDER_CONN *conn_arg
648652
) {
@@ -660,6 +664,7 @@ bool spider_fields::check_conn_same_conn(
660664
DBUG_RETURN(FALSE);
661665
}
662666

667+
/* Remove all conn holders with false checked_for_same_conn */
663668
bool spider_fields::remove_conn_if_not_checked(
664669
) {
665670
SPIDER_CONN_HOLDER *conn_holder;
@@ -1468,6 +1473,7 @@ group_by_handler *spider_create_group_by_handler(
14681473
goto skip_free_table_holder;
14691474
}
14701475
memset(dbton_bitmap, 0, spider_bitmap_size(SPIDER_DBTON_SIZE));
1476+
/* Find all backends used by the first table. */
14711477
for (roop_count = 0; roop_count < (int) share->use_dbton_count; ++roop_count)
14721478
{
14731479
dbton_id = share->use_sql_dbton_ids[roop_count];
@@ -1498,6 +1504,7 @@ group_by_handler *spider_create_group_by_handler(
14981504
DBUG_PRINT("info",("spider can not add a table"));
14991505
goto skip_free_table_holder;
15001506
}
1507+
/* Find all backends used by the current table */
15011508
memset(dbton_bitmap_tmp, 0, spider_bitmap_size(SPIDER_DBTON_SIZE));
15021509
for (roop_count = 0; roop_count < (int) share->use_dbton_count; ++roop_count)
15031510
{
@@ -1509,6 +1516,7 @@ group_by_handler *spider_create_group_by_handler(
15091516
spider_set_bit(dbton_bitmap_tmp, dbton_id);
15101517
}
15111518
}
1519+
/* Intersect to get common backends used by all tables (so far) */
15121520
for (roop_count = 0;
15131521
roop_count < spider_bitmap_size(SPIDER_DBTON_SIZE); ++roop_count)
15141522
{
@@ -1758,7 +1766,7 @@ group_by_handler *spider_create_group_by_handler(
17581766

17591767
while ((from = from->next_local))
17601768
{
1761-
fields->clear_conn_holder_from_conn();
1769+
fields->clear_conn_holder_checked();
17621770

17631771
if (from->table->part_info)
17641772
{
@@ -1799,10 +1807,13 @@ group_by_handler *spider_create_group_by_handler(
17991807
DBUG_PRINT("info",("spider conn=%p", conn));
18001808
if (!fields->check_conn_same_conn(conn))
18011809
{
1802-
DBUG_PRINT("info",("spider connection %p can not be used for this query with locking",
1803-
conn));
18041810
if (lock_mode)
1811+
{
1812+
DBUG_PRINT("info", ("spider connection %p can not be used for this "
1813+
"query with locking",
1814+
conn));
18051815
goto skip_free_fields;
1816+
}
18061817
continue;
18071818
}
18081819
if (fields->add_link_idx(conn->conn_holder_for_direct_join, spider, roop_count))
@@ -1820,6 +1831,10 @@ group_by_handler *spider_create_group_by_handler(
18201831
goto skip_free_fields;
18211832
}
18221833
}
1834+
/* Do not create if all conn holders have been removed. This
1835+
happens if the current table does not share usable conns with
1836+
the first table. One typical example is when the current table
1837+
is located on a different server from the first table. */
18231838
if (!fields->has_conn_holder())
18241839
{
18251840
goto skip_free_fields;

0 commit comments

Comments
 (0)