docs icon indicating copy to clipboard operation
docs copied to clipboard

Use decimal data type for the TRUNCATE argument to address the `Truncated incorrect INTEGER value: '' warning`

Open yahonda opened this issue 1 year ago • 2 comments

What is changed, added or deleted? (Required)

This pull request replaces the data type for the truncate argument from varchar to decimal because the current example raises the Truncated incorrect INTEGER value: '' warning.

  • Current example that raises the Truncated incorrect INTEGER value: '' warning.
mysql> use test;
Database changed
mysql> create table t(id int primary key, a varchar(10) not null);
Query OK, 0 rows affected (0.07 sec)

mysql> desc select * from t where truncate(a, " ") = '1';
+-------------------------+----------+-----------+---------------+---------------------------------------------------+
| id                      | estRows  | task      | access object | operator info                                     |
+-------------------------+----------+-----------+---------------+---------------------------------------------------+
| Selection_5             | 8000.00  | root      |               | eq(truncate(cast(test.t.a, double BINARY), 0), 1) |
| └─TableReader_7         | 10000.00 | root      |               | data:TableFullScan_6                              |
|   └─TableFullScan_6     | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo                    |
+-------------------------+----------+-----------+---------------+---------------------------------------------------+
3 rows in set, 2 warnings (0.00 sec)

mysql> show warnings;
+---------+------+------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                      |
+---------+------+------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: ''                                                                                        |
| Warning | 1105 | Scalar function 'truncate'(signature: TruncateReal, return type: double) is not supported to push down to storage layer now. |
+---------+------+------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql>
mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v8.1.0
Edition: Community
Git Commit Hash: 945d07c5d5c7a1ae212f6013adfb187f2de24b23
Git Branch: HEAD
UTC Build Time: 2024-05-21 03:52:40
GoVersion: go1.21.10
Race Enabled: false
Check Table Before Drop: false
Store: tikv
1 row in set (0.00 sec)

mysql>
  • Updated example that does not raise the Truncated incorrect INTEGER value: '' warning.
mysql> drop table t;
Query OK, 0 rows affected (0.19 sec)

mysql> create table t(id int primary key, a decimal(10, 2) not null);
Query OK, 0 rows affected (0.07 sec)

mysql> desc select * from t where truncate(a, 0) = 1;
+-------------------------+----------+-----------+---------------+--------------------------------+
| id                      | estRows  | task      | access object | operator info                  |
+-------------------------+----------+-----------+---------------+--------------------------------+
| Selection_5             | 8000.00  | root      |               | eq(truncate(test.t.a, 0), 1)   |
| └─TableReader_7         | 10000.00 | root      |               | data:TableFullScan_6           |
|   └─TableFullScan_6     | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+--------------------------------+
3 rows in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                               |
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1105 | Scalar function 'truncate'(signature: TruncateDecimal, return type: decimal(8,0)) is not supported to push down to storage layer now. |
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql>

Which TiDB version(s) do your changes apply to? (Required)

Tips for choosing the affected version(s):

By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.

For details, see tips for choosing the affected versions.

  • [ ] master (the latest development version)
  • [ ] v8.3 (TiDB 8.3 versions)
  • [ ] v8.2 (TiDB 8.2 versions)
  • [ ] v8.1 (TiDB 8.1 versions)
  • [ ] v8.0 (TiDB 8.0 versions)
  • [ ] v7.5 (TiDB 7.5 versions)
  • [ ] v7.1 (TiDB 7.1 versions)
  • [ ] v6.5 (TiDB 6.5 versions)
  • [ ] v6.1 (TiDB 6.1 versions)
  • [ ] v5.4 (TiDB 5.4 versions)
  • [ ] v5.3 (TiDB 5.3 versions)
  • [ ] v5.2 (TiDB 5.2 versions)

What is the related PR or file link(s)?

  • This PR is translated from:
  • Other reference link(s): The current change has been made via #13682

This document says "Truncate to specified number of decimal places". https://docs.pingcap.com/tidb/stable/numeric-functions-and-operators

TRUNCATE() Truncate to specified number of decimal places

Do your changes match any of the following descriptions?

  • [ ] Delete files
  • [ ] Change aliases
  • [ ] Need modification after applied to another branch
  • [ ] Might cause conflicts after applied to another branch

yahonda avatar Aug 13 '24 05:08 yahonda

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Once this PR has been reviewed and has the lgtm label, please assign csuzhangxc for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

ti-chi-bot[bot] avatar Aug 13 '24 05:08 ti-chi-bot[bot]

@xzhangxian1008 Could you please help review this PR? Thanks! This example is introduced in https://github.com/pingcap/docs-cn/pull/14054

Oreoxmt avatar Aug 13 '24 05:08 Oreoxmt