-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
*: cut off duration.fsp in chunk #7043
*: cut off duration.fsp in chunk #7043
Conversation
/run-all-tests |
util/chunk/row.go
Outdated
@@ -88,7 +89,8 @@ func (r Row) GetTime(colIdx int) types.Time { | |||
// GetDuration returns the Duration value with the colIdx. | |||
func (r Row) GetDuration(colIdx int) types.Duration { |
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.
Does this change affect the benchmark of GetDuration
?
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.
I will benchmark later, but it seems will allocate more a types.Duration
than before, but this is just as GetTime
does...
expression/builtin_time.go
Outdated
if err != nil { | ||
return nil, err | ||
} | ||
bf.tp.Decimal = mathutil.Max(arg0Dec, arg1Dec) |
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.
this is a bugfix?
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.
this decimal field is no use before this PR, so it got wrong value but not affect the user, but now if the duration comes from chunk.row
will need it to compensate missed fsp info.
expression/integration_test.go
Outdated
@@ -1307,13 +1307,13 @@ func (s *testIntegrationSuite) TestTimeBuiltin(c *C) { | |||
|
|||
// test time | |||
result = tk.MustQuery("select time('2003-12-31 01:02:03')") | |||
result.Check(testkit.Rows("01:02:03")) | |||
result.Check(testkit.Rows("01:02:03.000000")) |
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.
this result is different from mysql:
MySQL(localhost:3306) > select time('2003-12-31 01:02:03');
+-----------------------------+
| time('2003-12-31 01:02:03') |
+-----------------------------+
| 01:02:03 |
+-----------------------------+
1 row in set (0.00 sec)
expression/integration_test.go
Outdated
result = tk.MustQuery("select time('2003-12-31 01:02:03.000123')") | ||
result.Check(testkit.Rows("01:02:03.000123")) | ||
result = tk.MustQuery("select time('01:02:03.000123')") | ||
result.Check(testkit.Rows("01:02:03.000123")) | ||
result = tk.MustQuery("select time('01:02:03')") | ||
result.Check(testkit.Rows("01:02:03")) | ||
result.Check(testkit.Rows("01:02:03.000000")) |
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.
ditto
There are still some truncate test cases give the different result to MySQL(even in master branch), https://github.com/pingcap/tidb-test/pull/574/commits/21411bae6f795c51b152383dcd2dd06d4e3c94ea |
LGTM But we still need some benchmarks to know the exact performance regression. |
types/etc.go
Outdated
return true | ||
} | ||
return false | ||
} | ||
|
||
// IsStr returns a boolean indicating | ||
// whether the field type is a string type. | ||
func IsStr(ft *FieldType) bool { |
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.
s/ IsStr/ IsString
util/chunk/row.go
Outdated
@@ -20,6 +20,7 @@ import ( | |||
"github.com/pingcap/tidb/types" | |||
"github.com/pingcap/tidb/types/json" | |||
"github.com/pingcap/tidb/util/hack" | |||
"time" |
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.
put this line to line17
expression/builtin_time.go
Outdated
@@ -5370,3 +5401,19 @@ func (b *builtinLastDaySig) evalTime(row types.Row) (types.Time, bool, error) { | |||
} | |||
return ret, false, nil | |||
} | |||
|
|||
func timePrecision(ctx sessionctx.Context, expression Expression) (int, error) { |
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.
add a comment for this function.
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.
-
- name is not very suitable, it was renamed and add comments in new commit.
expression/builtin_time.go
Outdated
if isNil || err != nil { | ||
return 0, errors.Trace(err) | ||
} | ||
if n := strings.LastIndexByte(str, '.'); n >= 0 { |
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.
This check can be replaced by function GetFsp
expression/integration_test.go
Outdated
@@ -2663,7 +2663,7 @@ func (s *testIntegrationSuite) TestCompareBuiltin(c *C) { | |||
tk.MustExec(`insert into t2 values(1, 1.1, "2017-08-01 12:01:01", "12:01:01", "abcdef", 0b10101)`) | |||
|
|||
result = tk.MustQuery("select coalesce(NULL, a), coalesce(NULL, b, a), coalesce(c, NULL, a, b), coalesce(d, NULL), coalesce(d, c), coalesce(NULL, NULL, e, 1), coalesce(f), coalesce(1, a, b, c, d, e, f) from t2") | |||
result.Check(testkit.Rows(fmt.Sprintf("1 1.1 2017-08-01 12:01:01 12:01:01 %s 12:01:01 abcdef 21 1", time.Now().In(tk.Se.GetSessionVars().GetTimeZone()).Format("2006-01-02")))) | |||
result.Check(testkit.Rows(fmt.Sprintf("1 1.1 2017-08-01 12:01:01 12:01:01.000000 %s 12:01:01 abcdef 21 1", time.Now().In(tk.Se.GetSessionVars().GetTimeZone()).Format("2006-01-02")))) |
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.
Is this compatible with mysql?
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.
oh~ that's bug...fixed in new commits
types/fsp.go
Outdated
@@ -22,6 +22,8 @@ import ( | |||
) | |||
|
|||
const ( | |||
// WaitFillFsp is fsp need fill by caller if they want to use fsp. | |||
WaitFillFsp = -2 |
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 will the caller want to us fsp?
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.
-
- the old way needs GetDuration caller to check whether
result.fsp == WaitFillFsp
than refill Fsp or do nothing...that's buggy.
- the old way needs GetDuration caller to check whether
Now force pass fillFsp
paramter in GetDuration
(also add some comments) and no longer need this flag. PTAL~thx
@lysu |
expression/builtin_time.go
Outdated
@@ -5370,3 +5401,16 @@ func (b *builtinLastDaySig) evalTime(row types.Row) (types.Time, bool, error) { | |||
} | |||
return ret, false, nil | |||
} | |||
|
|||
// expressionFsp calculates the fsp from given expression. | |||
func expressionFsp(ctx sessionctx.Context, expression Expression) (int, error) { |
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.
s/ expressionFsp/ getExpressionFsp
@@ -1249,7 +1249,7 @@ func (s *testInferTypeSuite) createTestCase4TimeFuncs() []typeInferTestCase { | |||
{"addtime(c_timestamp, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 4}, | |||
{"addtime(c_timestamp_d, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 0}, | |||
{"addtime(c_time, c_time)", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 15, 3}, | |||
{"addtime(c_time_d, c_time)", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 15, 0}, | |||
{"addtime(c_time_d, c_time)", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 15, 3}, |
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.
Do the changes in this file be more reasonable or more compatible?
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.
Yes, in previous we didn't infer decimal and always be zero, but in MySQL takes that.
mysql> select version();
+---------------------------+
| version() |
+---------------------------+
| 5.7.22-0ubuntu18.04.1-log |
+---------------------------+
1 row in set (0.00 sec)
mysql> select addtime(c_time_d, c_time) from t;
Field 1: `addtime(c_time_d, c_time)`
Catalog: `def`
Database: ``
Table: ``
Org_table: ``
Type: TIME
Collation: binary (63)
Length: 14
Max_length: 0
Decimals: 3
Flags: BINARY
0 rows in set (0.00 sec)
types/row.go
Outdated
@@ -42,7 +42,9 @@ type Row interface { | |||
GetTime(colIdx int) Time | |||
|
|||
// GetDuration returns the Duration value with the colIdx. | |||
GetDuration(colIdx int) Duration | |||
// fillFsp is needed for refill fsp info if duration came from chunk.Row which is no longer store fsp info. | |||
// if caller make sure that data from Datum or only use Duration.Duration properties can pass 0 as fillFsp |
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.
s/ is/ If
add .
at the end of this comment
types/row.go
Outdated
@@ -42,7 +42,9 @@ type Row interface { | |||
GetTime(colIdx int) Time | |||
|
|||
// GetDuration returns the Duration value with the colIdx. | |||
GetDuration(colIdx int) Duration | |||
// fillFsp is needed for refill fsp info if duration came from chunk.Row which is no longer store fsp info. | |||
// if caller make sure that data from Datum or only use Duration.Duration properties can pass 0 as fillFsp |
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.
s/ is/ If
add .
at the end of this comment
types/time.go
Outdated
@@ -812,7 +813,7 @@ func (d Duration) String() string { | |||
} | |||
|
|||
fmt.Fprintf(&buf, "%02d:%02d:%02d", hours, minutes, seconds) | |||
if d.Fsp > 0 { | |||
if d.Fsp > 0 && fraction >= 0 { |
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.
add a comment for this check
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.
check fraction seems useless....I removed it
types/datum.go
Outdated
if err != nil { | ||
return ret, errors.Trace(err) | ||
} | ||
if timeNum > MaxDuration && timeNum < 10000000000 { |
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.
what if timeNum > 10000000000
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.
timeNum > MaxDuration and < 10000000000 must be a wrong value..
but timeNum > 10000000000 will try treat as 'YYYYMMDDHHmmss'
specially timeNum < 0 and timeNum < -10000000000 should NOT treat as 'YYYYMMDDHHmmss'
I add some comments for this if
~
expression/builtin_time.go
Outdated
|
||
arg0Dec, err := expressionFsp(ctx, args[0]) | ||
if err != nil { | ||
return nil, err |
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.
errors.Trace(err)
and line 411
/run-all-tests tidb-test=pr/574 |
LGTM |
for master:
for this pr:
|
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.
rest LGTM
types/datum.go
Outdated
if err != nil { | ||
return ret, errors.Trace(err) | ||
} | ||
// For For huge numbers(>'0001-00-00 00-00-00') try full DATETIME in ParseDuration. |
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.
remove one For
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.
Done
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.
LGTM
What have you changed? (mandatory)
fsp
oftypes.Duration
fromChunk
to reduce memory in chunkThis PR is "easy way" to #7013 which is more right and more clear in theory, but with big change and be nightmare to both reviewee and reviewer, but I still think it must be done in future.
collation
,decimal
,length
is short-cut for some part coding but wrong for design.But this time, we solve chunk in this small PR first.
What is the type of the changes? (mandatory)
How has this PR been tested? (mandatory)
This change is