Skip to content

Instantly share code, notes, and snippets.

@sploiselle
Last active June 14, 2016 14:39
Show Gist options
  • Save sploiselle/a66de3daa0260ff9434e40201bb41f5f to your computer and use it in GitHub Desktop.
Save sploiselle/a66de3daa0260ff9434e40201bb41f5f to your computer and use it in GitHub Desktop.
index on decimal column EXPLAIN bug when encoding decimal

Summary

When creating an index on a column with type DECIMAL, EXPLAIN SELECT shows the indexed range it's retrieving as:

EXPLAIN SELECT decimalCol FROM t WHERE decimalCol>10;
+-------+------+------------------------------------------------------------------------------------------------+
| Level | Type |                                          Description                                           |
+-------+------+------------------------------------------------------------------------------------------------+
|     0 | scan | t@decimalIndex /<util/encoding/decimal.go:395: did not find terminator 0x0 in buffer 0x1401>-  |
+-------+------+------------------------------------------------------------------------------------------------+

However, the SELECT statement still executes, so it looks like it's just a bug with encoding the DECIMAL value in EXPLAIN's output.

INSERT INTO t VALUES (11.1);
SELECT decimalCol FROM t WHERE decimalCol>10;
+------------+
| decimalCol |
+------------+
|       11.1 |
+------------+

NOTE: Tested indexes created with INT, FLOAT, BOOL, DATE, TIMESTAMP, INTERVAL, STRING, and BYTE columns and there were no issues.

Steps to repro

Create table

CREATE TABLE t (decimalCol DECIMAL);

Create index on the DECIMAL column

CREATE INDEX decimalIndex ON t (decimalCol);

EXPLAIN SELECT demos bug

EXPLAIN SELECT decimalCol FROM t WHERE decimalCol>10;
+-------+------+------------------------------------------------------------------------------------------------+
| Level | Type |                                          Description                                           |
+-------+------+------------------------------------------------------------------------------------------------+
|     0 | scan | t@decimalIndex /<util/encoding/decimal.go:395: did not find terminator 0x0 in buffer 0x1401>-  |
+-------+------+------------------------------------------------------------------------------------------------+

Other tested table configurations

All of the following tables generate the same error

  • Column with precision and scale specified
CREATE TABLE t (decimalCol DECIMAL(9,2));
  • Table with primary key
CREATE TABLE t (id INT PRIMARY KEY, decimalCol DECIMAL);
  • Table with primary key; column with precision and scale identified
CREATE TABLE t (id INT PRIMARY KEY, decimalCol DECIMAL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment