-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
feat(tianmu): support add integer/decimal column DDL with default value. (#1187) #1208
feat(tianmu): support add integer/decimal column DDL with default value. (#1187) #1208
Conversation
Thanks for the contribution! Please review the labels and make any necessary changes. |
9f2bdbb
to
4146fa6
Compare
5d681ba
to
13f62b6
Compare
size_t no_nulls{no_rows}; | ||
int64_t min{0}; | ||
int64_t max{0}; | ||
bool int_not_null{false}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use AttributeTypeInfo::NotNull() to check whether the field is NULL? I guess int_not_null means has_default_value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.not null flag check is also a solution. in the scenario the alter table defined not null or null(same with tianmu), the
output is NULL. I just want to use GetValueFromField(it deals the default value logic) function to deal with the scenario, the std::variants store the value, it has the interface to decide whether it is null,if not null, what is the default value.
2 The current solution is also a proper way,not to consider the null flag (or it has been considered in GetValueFromField)
3 the std::variant in gcc8 has bugs, what we supported is gcc9.3, if we do not upgrade debian gcc to 9.3, another solution is to use boost:variant, but not recommended. It is better to upgrade the debian CI to gcc9.3 @wisehead
@@ -112,7 +112,7 @@ static core::Value GetValueFromField(Field *f) { | |||
// convert to UTC | |||
if (!common::IsTimeStampZero(my_time)) { | |||
my_bool myb; | |||
my_time_t secs_utc = current_txn_->Thd()->variables.time_zone->TIME_to_gmt_sec(&my_time, &myb); | |||
my_time_t secs_utc = f->table->in_use->variables.time_zone->TIME_to_gmt_sec(&my_time, &myb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add some comments here, I don't quite understand the code changes here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f->table->in_use is to get the THD pionter, current_txn_->Thd() is also to get the THD pointer. I want to store default value from the function GetValueFromField, but in some senario, the cureent_txn is not initialized and pointed to null. I find f->table->in_use is not nullptr, so i change the code to f->table->in_use.
@@ -1634,7 +1634,13 @@ bool ha_tianmu::inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha | |||
DBUG_RETURN(false); | |||
} else if (!(ha_alter_info->handler_flags & ~TIANMU_SUPPORTED_ALTER_ADD_DROP_ORDER)) { | |||
std::vector<Field *> v_old(table_share->field, table_share->field + table_share->fields); | |||
std::vector<Field *> v_new(altered_table->s->field, altered_table->s->field + altered_table->s->fields); | |||
|
|||
Field_iterator_table it_field; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also add some comments here, does original code work? or you change it because it's just ugly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because i want to get the default value from the filed, but altered_table->s->field's table pointer is null, can not to get the default value. alter_table->field's table pointer is correct, so i use it to store the fields;
@DandreChen @hustjieke please also review the code. |
d2eb312
to
62cd214
Compare
Codecov ReportBase: 43.38% // Head: 43.33% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## stonedb-5.7-dev #1208 +/- ##
===================================================
- Coverage 43.38% 43.33% -0.05%
===================================================
Files 1830 1830
Lines 396143 396147 +4
===================================================
- Hits 171853 171677 -176
- Misses 224290 224470 +180
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
62cd214
to
5ed4b4b
Compare
ACK. |
|
||
create table t3(id int,name varchar(5)) ; | ||
insert into t3 values(1,'AAA'),(2,'BBB'); | ||
alter table t3 add column age int not null default 66; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls, add some case for errors. such as using wrong default value.
Taking the following as an instance.
The column type is char
but using integer as a default value, the type and default value is mismatch. or the default will lead to type overflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
F.I.Y: Just only change the default value.
ALTER TABLE table_name ALTER COLUMN column_name SET DEFAULT 'literal';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- ok, i will try to add some wrong default value; maybe it will be intercepted by sql layer, i will test it.(confirmed, it wll be intercepted by sql layer, better not to add this mtr);
- "Just only change the default value" is a related sceanrio, i will add this MTR.
storage/tianmu/handler/ha_tianmu.h
Outdated
@@ -23,6 +23,7 @@ | |||
|
|||
namespace Tianmu { | |||
namespace handler { | |||
extern Tianmu::core::Value GetValueFromField(Field *f); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or perhaps, put it in .cpp, in which we will use this function, is a better way. And, will not contaminate the other files which includes this .h file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, i will fix it;
…ue. (stoneatom#1187) [summary] check the default value of field,please see tianmu_attr.cpp for details: 1 if field is integer type but not real type; 2 if field is integer type and also real type; 2if field is not integer type;
5ed4b4b
to
82e8dca
Compare
|
||
create table t2(id int,name varchar(5)) ; | ||
insert into t2 values(1,'AAA'),(2,'BBB'); | ||
alter table t2 add column age int not null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when the type is varchar not null,what will happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it is convenient,please fix it together when the type is varchar not null
as below case:
create table ttt(id int,name varchar(5));
insert into ttt values(1,'AAA'),(2,'BBB');
alter table ttt add column age varchar(5) not null;
select * from ttt;
The current inplace ddl solution(include the original) seems that it does not consider the delete row scenario, need a deeper check. |
|
Alter Table Add Column Design(High Level) 1 current status 1.1 scenario: default value is NULL and rows are not ever deleted[supported] 1.2 scenario: default value is NULL and rows are ever deleted; 1.3 scenario:default value is not NULL 2 How to get and create data file
2.7 update version file of attr; 3 How to get default value 4 Test for performance |
|
lujiashun seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Summary about this PR
Issue Number: close #1187
[summary]
check the default value of field,please see tianmu_attr.cpp for details:
Tests Check List
Changelog
Documentation