-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
WIP Bb main mdev 15621 #5111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mariadb-YuchenPei
wants to merge
2
commits into
main
Choose a base branch
from
bb-main-mdev-15621
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
WIP Bb main mdev 15621 #5111
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -400,7 +400,7 @@ bool partition_info::set_up_default_partitions(THD *thd, handler *file, | |
| num_parts= 2; | ||
| use_default_num_partitions= false; | ||
| } | ||
| else if (part_type != HASH_PARTITION) | ||
| else if (part_type != HASH_PARTITION && !is_range_interval()) | ||
| { | ||
| const char *error_string; | ||
| if (part_type == RANGE_PARTITION) | ||
|
|
@@ -891,6 +891,34 @@ bool partition_info::vers_set_hist_part(THD *thd, uint *create_count) | |
| return false; | ||
| } | ||
|
|
||
| /* | ||
| Determine the number of range interval partitions to create, like | ||
| partition_info::vers_set_hist_part. | ||
| */ | ||
| bool partition_info::range_interval_set_count(THD* thd, uint *create_count) | ||
| { | ||
| partition_element *el= partitions.elem(partitions.elements - 1); | ||
| Item *item= el->get_col_val(0).item_expression; | ||
| MYSQL_TIME cur_time, end_time; | ||
| thd->variables.time_zone->gmt_sec_to_TIME(&end_time, thd->query_start()); | ||
| longlong cur= item->val_datetime_packed(thd); | ||
| unpack_time(cur, &cur_time, MYSQL_TIMESTAMP_DATETIME); | ||
| longlong end= pack_time(&end_time); | ||
| *create_count= 0; | ||
| while (cur <= end) | ||
|
mariadb-YuchenPei marked this conversation as resolved.
|
||
| { | ||
| if (date_add_interval(thd, &cur_time, int_type, interval)) | ||
| return true; | ||
| cur= pack_time(&cur_time); | ||
| ++*create_count; | ||
| if (*create_count == MAX_PARTITIONS - partitions.elements + 1) | ||
| { | ||
| my_error(ER_TOO_MANY_PARTITIONS_ERROR, MYF(0)); | ||
| return true; | ||
| } | ||
| } | ||
|
mariadb-YuchenPei marked this conversation as resolved.
|
||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| @brief Run fast_alter_partition_table() to add new history partitions | ||
|
|
@@ -1014,6 +1042,101 @@ bool vers_create_partitions(THD *thd, TABLE_LIST* tl, uint num_parts) | |
| return result; | ||
| } | ||
|
|
||
| /* | ||
| similar to vers_create_partitions, create range interval partitions | ||
| */ | ||
| bool range_interval_create_partitions(THD* thd, TABLE_LIST* tl, uint num_parts) | ||
| { | ||
| bool result= true; | ||
| Table_specification_st create_info; | ||
| Alter_info alter_info; | ||
| TABLE *table= tl->table; | ||
| /* TODO: this may still trigger MSAN unitialised? */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| bool save_no_write_to_binlog= thd->lex->no_write_to_binlog; | ||
| thd->lex->no_write_to_binlog= true; | ||
|
|
||
| DBUG_ASSERT(!thd->is_error()); | ||
| DBUG_ASSERT(num_parts); | ||
|
|
||
| { | ||
| alter_info.reset(); | ||
| alter_info.partition_flags= ALTER_PARTITION_ADD; | ||
| create_info.init(); | ||
| create_info.alter_info= &alter_info; | ||
| Alter_table_ctx alter_ctx(thd, tl, 1, &table->s->db, &table->s->table_name); | ||
|
|
||
| MDL_REQUEST_INIT(&tl->mdl_request, MDL_key::TABLE, tl->db.str, | ||
| tl->table_name.str, MDL_SHARED_NO_WRITE, MDL_TRANSACTION); | ||
| if (thd->mdl_context.acquire_lock(&tl->mdl_request, | ||
| thd->variables.lock_wait_timeout)) | ||
| goto exit; | ||
| table->mdl_ticket= tl->mdl_request.ticket; | ||
|
|
||
| create_info.db_type= table->s->db_type(); | ||
| DBUG_ASSERT(create_info.db_type); | ||
|
|
||
| partition_info *part_info= new partition_info(); | ||
| if (unlikely(!part_info)) | ||
| { | ||
| my_error(ER_OUT_OF_RESOURCES, MYF(0)); | ||
| goto exit; | ||
| } | ||
| part_info->use_default_num_partitions= false; | ||
| part_info->use_default_num_subpartitions= false; | ||
| part_info->num_parts= num_parts; | ||
| part_info->num_subparts= table->part_info->num_subparts; | ||
| part_info->subpart_type= table->part_info->subpart_type; | ||
| part_info->num_columns= table->part_info->num_columns; | ||
| part_info->part_type= RANGE_PARTITION; | ||
| /* for partition_info::fix_parser_data to exit early */ | ||
| part_info->int_type= table->part_info->int_type; | ||
|
mariadb-YuchenPei marked this conversation as resolved.
|
||
|
|
||
| thd->work_part_info= part_info; | ||
| bool partition_changed= false; | ||
| bool fast_alter_partition= false; | ||
| if (prep_alter_part_table(thd, table, &alter_info, &create_info, | ||
| &partition_changed, &fast_alter_partition)) | ||
| { | ||
| my_error(ER_INTERNAL_ERROR, MYF(ME_WARNING), | ||
| tl->db.str, tl->table_name.str); | ||
| goto exit; | ||
| } | ||
|
mariadb-YuchenPei marked this conversation as resolved.
|
||
| if (!fast_alter_partition) | ||
| { | ||
| my_error(ER_INTERNAL_ERROR, MYF(ME_WARNING), | ||
| tl->db.str, tl->table_name.str); | ||
| goto exit; | ||
| } | ||
| DBUG_ASSERT(partition_changed); | ||
| if (mysql_prepare_alter_table(thd, table, &create_info, &alter_info, | ||
| &alter_ctx)) | ||
| { | ||
| my_error(ER_INTERNAL_ERROR, MYF(ME_WARNING), | ||
| tl->db.str, tl->table_name.str); | ||
| goto exit; | ||
| } | ||
|
|
||
| alter_info.db= alter_ctx.db; | ||
| alter_info.table_name= alter_ctx.table_name; | ||
| if (fast_alter_partition_table(thd, table, &alter_info, &alter_ctx, | ||
| &create_info, tl)) | ||
| { | ||
| my_error(ER_INTERNAL_ERROR, MYF(ME_WARNING), | ||
| tl->db.str, tl->table_name.str); | ||
| goto exit; | ||
| } | ||
| } | ||
|
|
||
| result= false; | ||
| // NOTE: we have to return DA_EMPTY for new command | ||
| DBUG_ASSERT(thd->get_stmt_da()->is_ok()); | ||
| thd->get_stmt_da()->reset_diagnostics_area(); | ||
| thd->variables.option_bits|= OPTION_BINLOG_THIS; | ||
|
|
||
| exit: | ||
| thd->lex->no_write_to_binlog= save_no_write_to_binlog; | ||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| Warn at the end of DML command if the last history partition is out of LIMIT. | ||
|
|
@@ -2166,7 +2289,7 @@ int partition_info::fix_partition_values(THD *thd, | |
| } | ||
| part_elem->range_value= val->value; | ||
| } | ||
| col_val->fixed= 2; | ||
| col_val->fixed= TRUE; | ||
| DBUG_RETURN(FALSE); | ||
| } | ||
|
|
||
|
|
@@ -2219,12 +2342,11 @@ bool partition_info::fix_column_value_functions(THD *thd, | |
| uint part_id) | ||
| { | ||
| uint n_columns= part_field_list.elements; | ||
| bool result= FALSE; | ||
| uint i; | ||
| part_column_list_val *col_val= val->col_val_array; | ||
| DBUG_ENTER("partition_info::fix_column_value_functions"); | ||
|
|
||
| if (col_val->fixed > 1) | ||
| if (col_val->fixed) | ||
| { | ||
| DBUG_RETURN(FALSE); | ||
| } | ||
|
|
@@ -2247,8 +2369,7 @@ bool partition_info::fix_column_value_functions(THD *thd, | |
|
|
||
| if (!(column_item= get_column_item(column_item, field))) | ||
| { | ||
| result= TRUE; | ||
| goto end; | ||
| DBUG_RETURN(TRUE); | ||
| } | ||
| Sql_mode_instant_set sms(thd, 0); | ||
| save_got_warning= thd->got_warning; | ||
|
|
@@ -2257,22 +2378,19 @@ bool partition_info::fix_column_value_functions(THD *thd, | |
| thd->got_warning) | ||
| { | ||
| my_error(ER_WRONG_TYPE_COLUMN_VALUE_ERROR, MYF(0)); | ||
| result= TRUE; | ||
| goto end; | ||
| DBUG_RETURN(TRUE); | ||
| } | ||
| thd->got_warning= save_got_warning; | ||
| if (!(val_ptr= (uchar*) thd->memdup(field->ptr, len))) | ||
| { | ||
| result= TRUE; | ||
| goto end; | ||
| DBUG_RETURN(TRUE); | ||
| } | ||
| col_val->column_value= val_ptr; | ||
| } | ||
| } | ||
| col_val->fixed= 2; | ||
| col_val->fixed= TRUE; | ||
| } | ||
| end: | ||
| DBUG_RETURN(result); | ||
| DBUG_RETURN(FALSE); | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -2325,6 +2443,7 @@ bool partition_info::fix_parser_data(THD *thd) | |
| partition_element *part_elem; | ||
| uint num_elements; | ||
| uint i= 0, j, k; | ||
| int sql_command= thd_sql_command(thd); | ||
| DBUG_ENTER("partition_info::fix_parser_data"); | ||
|
|
||
| if (!(part_type == RANGE_PARTITION || | ||
|
|
@@ -2339,13 +2458,25 @@ bool partition_info::fix_parser_data(THD *thd) | |
| DBUG_RETURN(true); | ||
| } | ||
| /* If not set, use DEFAULT = 2 for CREATE and ALTER! */ | ||
| if ((thd_sql_command(thd) == SQLCOM_CREATE_TABLE || | ||
| thd_sql_command(thd) == SQLCOM_ALTER_TABLE) && | ||
| if ((sql_command == SQLCOM_CREATE_TABLE || | ||
| sql_command == SQLCOM_ALTER_TABLE) && | ||
| key_algorithm == KEY_ALGORITHM_NONE) | ||
| key_algorithm= KEY_ALGORITHM_55; | ||
| } | ||
| DBUG_RETURN(FALSE); | ||
| } | ||
| /* | ||
| TODO(MDEV-15621): we exit here for range interval partitions | ||
| because if this is called from prep_alter_part_table then | ||
| partition data is not calculated (in | ||
| check_range_interval_constants) yet. But maybe we shouldn't exit | ||
| here in user CREATE/ALTER TABLE statements for other checks. | ||
| */ | ||
| if (sql_command != SQLCOM_CREATE_TABLE && | ||
| sql_command != SQLCOM_ALTER_TABLE && is_range_interval()) | ||
| { | ||
| DBUG_RETURN(FALSE); | ||
| } | ||
| if (is_sub_partitioned() && list_of_subpart_fields) | ||
| { | ||
| /* KEY subpartitioning, check ALGORITHM = N. Should not pass the parser! */ | ||
|
|
@@ -2790,6 +2921,21 @@ bool partition_info::vers_init_info(THD * thd) | |
| return false; | ||
| } | ||
|
|
||
| bool partition_info::set_interval(THD* thd, Item* ival, interval_type type, | ||
| const char *table_name) | ||
| { | ||
| bool error= get_interval_value(thd, ival, type, &interval) || | ||
| interval.neg || interval.second_part || | ||
| !(interval.year || interval.month || interval.day || interval.hour || | ||
| interval.minute || interval.second); | ||
| if (error) | ||
| { | ||
| my_error(ER_PART_WRONG_VALUE, MYF(0), table_name, "INTERVAL"); | ||
| return true; | ||
| } | ||
| int_type= type; | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| Assign INTERVAL and STARTS for SYSTEM_TIME partitions. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.