@@ -73,6 +73,7 @@ extern int g_osql_ready;
7373extern int gbl_goslow ;
7474extern int gbl_partial_indexes ;
7575
76+ int gbl_enable_partitioned_table_merge_resume = 0 ;
7677int gbl_master_sends_query_effects = 1 ;
7778int gbl_toblock_random_deadlock_trans ;
7879int gbl_toblock_random_verify_error ;
@@ -6312,6 +6313,7 @@ static int start_schema_change_tran_wrapper_merge(const char *tblname,
63126313 alter_sc -> force_rebuild = 1 ; /* we are moving rows here */
63136314 /* alter only in parallel mode for live */
63146315 alter_sc -> scanmode = SCAN_PARALLEL ;
6316+ alter_sc -> resume = sc -> resume ;
63156317 /* link the sc */
63166318 iq -> sc = alter_sc ;
63176319
@@ -6328,7 +6330,7 @@ static int start_schema_change_tran_wrapper_merge(const char *tblname,
63286330 /* link the alter */
63296331 iq -> sc -> sc_next = iq -> sc_pending ;
63306332 iq -> sc_pending = iq -> sc ;
6331- iq -> sc -> newdb = NULL ; /* lose ownership, otherwise double free */
6333+ if ( alter_sc -> nothrevent ) { iq -> sc -> newdb = NULL ; /* lose ownership, otherwise double free */ }
63326334
63336335 if (arg -> lockless ) {
63346336 * pview = timepart_reaquire_view (arg -> part_name );
@@ -6407,15 +6409,16 @@ static int _process_partitioned_table_merge(struct ireq *iq)
64076409 struct dbtable * first_shard = get_dbtable_by_name (first_shard_name );
64086410 free (first_shard_name );
64096411
6410- /* we need to move data */
6411- sc -> force_rebuild = 1 ;
6412+ const int latched_nothrevent = sc -> nothrevent ;
6413+
6414+ sc -> force_rebuild = 1 ; /* we need to move data */
6415+ sc -> nothrevent = 1 ; /* we need do_add_table / do_alter_table to run first */
6416+ sc -> finalize = 0 ;
64126417
64136418 if (!first_shard -> sqlaliasname ) {
64146419 /*
64156420 * create a table with the same name as the partition
64166421 */
6417- sc -> nothrevent = 1 ; /* we need do_add_table to run first */
6418- sc -> finalize = 0 ; /* make sure */
64196422 sc -> kind = SC_ADDTABLE ;
64206423
64216424 rc = start_schema_change_tran (iq , NULL );
@@ -6430,10 +6433,17 @@ static int _process_partitioned_table_merge(struct ireq *iq)
64306433 iq -> sc_pending = iq -> sc ;
64316434 } else {
64326435 /*
6433- * use the fast shard as the destination, after first altering it
6436+ * use the first shard as the destination, after first altering it
64346437 */
6435- sc -> nothrevent = 1 ; /* we need do_alter_table to run first */
6436- sc -> finalize = 0 ;
6438+ if (gbl_enable_partitioned_table_merge_resume ) {
6439+ sc -> partition .type = PARTITION_NONE ;
6440+ } else {
6441+ assert (sc -> partition .type == PARTITION_MERGE );
6442+ // If partitioned table merge resumes are disabled,
6443+ // then we keep the type equal to PARTITION_MERGE.
6444+ // There is code later on that blocks the resume if
6445+ // the type is PARTITION_MERGE.
6446+ }
64376447
64386448 strncpy (sc -> tablename , first_shard -> tablename , sizeof (sc -> tablename ));
64396449
@@ -6456,6 +6466,7 @@ static int _process_partitioned_table_merge(struct ireq *iq)
64566466 /* at this point we have created the future btree, launch an alter
64576467 * for each of the shards of the partition
64586468 */
6469+ sc -> nothrevent = latched_nothrevent ;
64596470 arg .s = sc ;
64606471 arg .s -> iq = iq ;
64616472 arg .part_name = strdup (sc -> tablename ); /*sc->tablename gets rewritten*/
0 commit comments