Skip to content
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

server: double type column from table should ignore its decimal (#21788) #21916

Merged
merged 4 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cmd/explaintest/r/select.result
Original file line number Diff line number Diff line change
Expand Up @@ -480,3 +480,18 @@ Projection_7 10000.00 root minus(Column#5, test.t.x)->Column#7
└─Sort_11 10000.00 root test.t.i:asc
└─TableReader_10 10000.00 root data:TableRangeScan_9
└─TableRangeScan_9 10000.00 cop[tikv] table:t range:[0,+inf], keep order:false, stats:pseudo
create table precise_types (
a BIGINT UNSIGNED NOT NULL,
b BIGINT NOT NULL,
c DECIMAL(21,1) NOT NULL,
d DOUBLE(21,1) NOT NULL
);
insert into precise_types values (
18446744073709551614,
-9223372036854775806,
99999999999999999999,
18446744073709551614
);
SELECT a, b, c, d FROM precise_types;
a b c d
18446744073709551614 -9223372036854775806 99999999999999999999.0 1.8446744073709552e19
15 changes: 15 additions & 0 deletions cmd/explaintest/t/select.test
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,18 @@ CREATE TABLE t (id int(10) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
);
explain select row_number() over( partition by i ) - x as rnk from t;

# for issue 21692
create table precise_types (
a BIGINT UNSIGNED NOT NULL,
b BIGINT NOT NULL,
c DECIMAL(21,1) NOT NULL,
d DOUBLE(21,1) NOT NULL
);
insert into precise_types values (
18446744073709551614,
-9223372036854775806,
99999999999999999999,
18446744073709551614
);
SELECT a, b, c, d FROM precise_types;
4 changes: 2 additions & 2 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,14 @@ func dumpTextRow(buffer []byte, columns []*ColumnInfo, row chunk.Row) ([]byte, e
buffer = dumpLengthEncodedString(buffer, tmp)
case mysql.TypeFloat:
prec := -1
if columns[i].Decimal > 0 && int(col.Decimal) != mysql.NotFixedDec {
if columns[i].Decimal > 0 && int(col.Decimal) != mysql.NotFixedDec && col.Table == "" {
prec = int(col.Decimal)
}
tmp = appendFormatFloat(tmp[:0], float64(row.GetFloat32(i)), prec, 32)
buffer = dumpLengthEncodedString(buffer, tmp)
case mysql.TypeDouble:
prec := types.UnspecifiedLength
if col.Decimal > 0 && int(col.Decimal) != mysql.NotFixedDec {
if col.Decimal > 0 && int(col.Decimal) != mysql.NotFixedDec && col.Table == "" {
prec = int(col.Decimal)
}
tmp = appendFormatFloat(tmp[:0], row.GetFloat64(i), prec, 64)
Expand Down