The EXPLAIN
fails with the query, but after 3 attempts with different search phrases (and nothing else) I got a successful execution.
Top offset:0 limit:51
GatherMerge [remote_0.volume DESC] partitions:all est_rows:51 query:[SELECT STRAIGHT_JOIN `keywords`.`id` AS `id`, `keywords`.`keyword` AS `keyword`, `keywords`.`volume` AS `volume`, `r1`.`priority` AS `priority`, COALESCE(`r2_2`.`count`,0) AS `cannibalization_pages` FROM (((`laravel_0`.`keywords-v2` as `k` STRAIGHT_JOIN `laravel_0`.`keywords` as `keywords` ) LEFT JOIN @ `laravel`.REMOTE(:: `laravel`.`r1`(0) AS SELECT (1!:>tinyint(3) unsigned NULL) AS `priority`,(1!:>char(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL) AS `keyword_id`) as `r1` WITH (table_convert_subselect = FALSE) ON (`keywords`.`id` = `r1`.`keyword_id`)) LEFT JOIN ( SELECT WITH(AGG_HINT_MERGE=true) `r2`.`keyword_id` AS `keyword_id`, CAST( COALESCE(SUM(`r2`.`count`),0) AS SIGNED) AS `count` FROM @ `laravel`.REMOTE(:: `laravel`.`r2`(0) AS SELECT (1!:>char(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL) AS `keyword_id`,(1!:>bigint(21) NOT NULL) AS `count`) as `r2` GROUP BY 1 ) AS `r2_2` ON (`keywords`.`id` = `r2_2`.`keyword_id`)) WHERE ((`k`.`location` = 'DK') AND (`k`.`language` = 'da') AND (MATCH (`k`.`keyword`) AGAINST ('test*')) AND (`keywords`.`id` = `k`.`id`)) ORDER BY 3 DESC LIMIT NULL OPTION(NO_QUERY_REWRITE=1, INTERPRETER_MODE=INTERPRET_FIRST)] alias:remote_0
Project [keywords.id, keywords.keyword, keywords.volume, r1.priority, COALESCE(r2_2.count,0) AS cannibalization_pages] est_rows:51 est_select_cost:706
TopSort limit:[?] [keywords.volume DESC]
HashJoin [r2_2.keyword_id = keywords.id] type:left
|---HashTableBuild alias:r2_2
| Project [r2.keyword_id, CAST(COALESCE($0,0) AS SIGNED) AS count] est_rows:352
| HashGroupBy [SUM(r2.count) AS $0] groups:[r2.keyword_id]
| TableScan r2 storage:list stream:yes est_table_rows:352
| Repartition [r0.keyword_id, count] AS r2 shard_key:[keyword_id] est_rows:352 est_select_cost:2,190 query:[CREATE RESULT TABLE r2 PARTITION BY (`keyword_id`) WITH (PARTITIONS=NULL, READERS=1, TAKEOVER_CONN=TRUE, BUFFERED_ROWS=NULL) AS SELECT WITH(LOCAL_SHUFFLE_GROUP_BY=1) STRAIGHT_JOIN `r0`.`keyword_id` AS `keyword_id`, COUNT(*) AS `count` FROM (@ `laravel`.REMOTE(:: `laravel`.`r0`(0) AS SELECT (1!:>char(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL) AS `keyword_id`,(1!:>bigint(20) unsigned NOT NULL) AS `page_id`) as `r0` STRAIGHT_JOIN `laravel_0`.`pages` as `pages` ) WHERE ((`pages`.`id` <> 15850902669311766255) AND (`pages`.`site_id` = 11) AND (`r0`.`page_id` = `pages`.`id`)) GROUP BY 1 OPTION(NO_QUERY_REWRITE=1, INTERPRETER_MODE=INTERPRET_FIRST)]
| ShuffleGroupBy [COUNT(*) AS count] groups:[r0.keyword_id]
| Filter [pages.id <> 15850902669311766255 AND pages.site_id = 11]
| NestedLoopJoin
| |---IndexSeek laravel.pages, PRIMARY KEY (id) scan:[id = r0.page_id] est_table_rows:470,067 est_filtered:31,176
| TableScan r0 storage:list stream:yes est_table_rows:365
| Repartition [page_keyword.keyword_id, page_keyword.page_id] AS r0 shard_key:[page_id] est_rows:365 query:[CREATE RESULT TABLE r0 PARTITION BY (`page_id`) WITH (PARTITIONS=NULL, READERS=1, TAKEOVER_CONN=TRUE, BUFFERED_ROWS=NULL) AS SELECT `page_keyword`.`keyword_id` AS `keyword_id`, `page_keyword`.`page_id` AS `page_id` FROM `laravel_0`.`page_keyword` as `page_keyword` WHERE ((`page_keyword`.`page_id` <> 15850902669311766255) AND (NOT ISNULL(`page_keyword`.`priority`))) OPTION(NO_QUERY_REWRITE=1, INTERPRETER_MODE=INTERPRET_FIRST)]
| Filter [page_keyword.page_id <> 15850902669311766255 AND page_keyword.priority IS NOT NULL]
| TableScan laravel.page_keyword, PRIMARY KEY (page_id, keyword_id) est_table_rows:105,937 est_filtered:365
HashJoin [r1.keyword_id = keywords.id] type:left
|---HashTableBuild alias:r1
| Repartition [page_keyword_1.priority, page_keyword_1.keyword_id] AS r1 shard_key:[keyword_id] est_rows:1 query:[CREATE RESULT TABLE r1 PARTITION BY (`keyword_id`) WITH (PARTITIONS=NULL, READERS=1, TAKEOVER_CONN=TRUE, BUFFERED_ROWS=NULL) AS SELECT `page_keyword_1`.`priority` AS `priority`, `page_keyword_1`.`keyword_id` AS `keyword_id` FROM `laravel_0`.`page_keyword` as `page_keyword_1` WHERE (`page_keyword_1`.`page_id` = 15850902669311766255) OPTION(NO_QUERY_REWRITE=1, INTERPRETER_MODE=INTERPRET_FIRST)]
| IndexRangeScan laravel.page_keyword AS page_keyword_1, PRIMARY KEY (page_id, keyword_id) scan:[page_id = 15850902669311766255] est_table_rows:6,301 est_filtered:1
NestedLoopJoin
|---IndexSeek laravel.keywords, PRIMARY KEY (id) scan:[id = k.id] est_table_rows:6,379,362 est_filtered:6,379,362
Filter [k.location = 'DK' AND k.language = 'da' AND (MATCH (k.keyword) AGAINST ('test*'))]
ColumnStoreScan laravel.`keywords-v2` AS k, KEY language (language, location) USING CLUSTERED COLUMNSTORE est_table_rows:6,485,143 est_filtered:33,921
The query you posted seems to resolve the issue, however its a little hard to tell for sure as the issue is periodically. But after 10 executions it hasn’t failed a single time and I even tried to target both aggregators directly.
I’ll implement the changes in the application and run some more tests.
Thank you for your help so far.