The cleanup is a bit more involved than I expected which is why I opened this ticket separately from MDEV-31787.
We can just factor out the portion in the gif, but it is not a "logical" block by it self, but rather a block before a for loop, and the if branch inside the for loop. There are (often minor) differences in the else branches, which may not be real differences, but require a bit more effort to the cleanup properly.
For example, I suspect the following are not real differences, and just redundancy in data structure
--- /home/ycp/source/mariadb-server/mdev-26151/repeats/rnd_next_internal.cc 2023-07-28 12:49:48.384561252 +1000
|
+++ /home/ycp/source/mariadb-server/mdev-26151/repeats/ft_read_internal.cc 2023-07-28 12:49:56.304500405 +1000
|
} else {
|
+ uint dbton_id = share->use_sql_dbton_ids[roop_count];
|
+ spider_db_handler *dbton_hdl = dbton_handler[dbton_id];
|
SPIDER_CONN *conn = conns[roop_count];
|
- ulong sql_type;
|
- sql_type= SPIDER_SQL_TYPE_SELECT_SQL;
|
- spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id];
|
I suspect share->use_sql_dbton_ids[roop_count] and conn->dbton_id are always the same value.
Another issues is the pattern in calls to spider_ping_table_mon_from_table(), and the patterns like the following in setup and teardown of queries
pthread_mutex_lock(&conn->mta_conn_mutex);
|
SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
|
conn->need_mon = &need_mons[roop_count];
|
DBUG_ASSERT(!conn->mta_conn_mutex_lock_already);
|
DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later);
|
conn->mta_conn_mutex_lock_already = TRUE;
|
conn->mta_conn_mutex_unlock_later = TRUE;
|
if ((error_num = spider_db_set_names(this, conn, roop_count)))
|
{
|
DBUG_ASSERT(conn->mta_conn_mutex_lock_already);
|
DBUG_ASSERT(conn->mta_conn_mutex_unlock_later);
|
conn->mta_conn_mutex_lock_already = FALSE;
|
conn->mta_conn_mutex_unlock_later = FALSE;
|
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
|
pthread_mutex_unlock(&conn->mta_conn_mutex);
|
They come in variants (sometimes missing the set / clear file pos part, sometimes without assigning to conn->need_mon) and is scattered all around the codebase, and need a proper cleanup based on understanding (see also my previous attempt in MDEV-29502 https://github.com/MariaDB/server/commit/3b5cecbacd46ea8607b4e5379633e60a98d71bc5). Therefore we defer this ticket to later, maybe when relevant to another task
Thanks for the testing. Pushed the following to 10.5
cc0faa1e3ea * upstream/bb-10.5-mdev-31788 upstream/10.5 MDEV-31788 Factor functions to reduce duplication around spider_check_and_init_casual_read in ha_spider.cc
0ba97e4dc62 * MDEV-31788 Factor out calls to spider_ping_table_mon_from_table in ha_spider.cc
9e1579788fc * MDEV-31788 Factor spider locking and unlocking code around sending queries
84067291b4f * MDEV-28360 Spider: remove #ifdef SPIDER_use_LEX_CSTRING_for_KEY_Field_name
f5b7c25e1e2 * MDEV-27643 Spider: remove #ifdef HA_CAN_BULK_ACCESS
e7570c7759e * MDEV-31788 Remove spider_file_pos
a81f419b06d * 10.5 upstream/bb-10.5-mdev-26178 MDEV-27648 remove #define HASH_UPDATE_WITH_HASH_VALUE
5d54e86c220 * MDEV-26178 spider: delete spd_environ.h
869c501ac36 * MDEV-27644 Spider: remove HANDLER_HAS_DIRECT_AGGREGATE
3a58291680c * MDEV-27662 remove SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE
84977868b1e * MDEV-27809 remove SPIDER_I_S_USE_SHOW_FOR_COLUMN
6287fb6e174 * MDEV-27652 remove #ifdef HA_HAS_CHECKSUM_EXTENDED
e8a5553cefd * MDEV-27808 remove SPIDER_LIKE_FUNC_HAS_GET_NEGATED
ab49b46d014 * MDEV-27664 remove SPIDER_SQL_CACHE_IS_IN_LEX
a1e5ee91117 * MDEV-27663 remove SPIDER_USE_CONST_ITEM_FOR_STRING_INT_REAL_DECIMAL_DATE_ITEM
5e98471df13 * MDEV-27811: remove SPIDER_MDEV_16246
8c8684b17f4 * MDEV-28226 Remove HANDLER_HAS_NEED_INFO_FOR_AUTO_INC
affcb0713d4 * MDEV-26178 spider: remove PARTITION_HAS_GET_PART_SPEC
6d0d09ebc2a * MDEV-26178 Spider: remove HANDLER_HAS_TOP_TABLE_FIELDS
1cb75d9a33a * MDEV-27660 Remove #ifdef SPIDER_HANDLER_START_BULK_INSERT_HAS_FLAGS
aaba68ac1ec * MDEV-28896 Spider: remove #ifdef SPIDER_UPDATE_ROW_HAS_CONST_NEW_DATA
f16c037753e * MDEV-28895 Spider: remove #ifdef HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT
0650c87d9bb * MDEV-27647 Spider: remove HANDLER_HAS_DIRECT_UPDATE_ROWS
d5d65b948b6 * MDEV-26178 Spider: remove HA_EXTRA_HAS_HA_EXTRA_USE_CMP_REF
de3dd942c00 * MDEV-28894 Spider: remove #ifdef HA_EXTRA_HAS_STARTING_ORDERED_INDEX_SCAN
64581c83e8c * MDEV-28893 Spider: remove #ifdef SPIDER_NET_HAS_THD
ba9bebd7194 * MDEV-28892 remove #ifdef SPIDER_Item_args_arg_count_IS_PROTECTED
05fafaf82d2 * MDEV-27646 remove SPIDER_HAS_HASH_VALUE_TYPE
I was planning to do it in two stages - the
MDEV-26178commits first. But I ended up pushing both sets of commits. I will still do the merge up in two stages.