tarantool / tarantool/tarantool
Inconsistent data types in SQL resultset when using SUM function with a subquery
Open
Nobody has claimed this yet.
bug
sql
- Dominant language
- Lua
- Stars
- 3.7k
- Forks
- 419
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 88
Description
Bug description
Calculating SUM of an integral subquery column returns 'decimal' column header with 'number' values.
- OS: Linux
- OS Version: Centos 8
- Architecture: amd64
Tarantool 2.10.0-beta2-286-gb494e762e
Target: Linux-x86_64-Release
Build options: cmake . -DCMAKE_INSTALL_PREFIX=/usr/local -DENABLE_BACKTRACE=ON
Compiler: /usr/lib64/ccache/cc /usr/lib64/ccache/c++
C_FLAGS: -fexceptions -funwind-tables -fno-common -fopenmp -msse2 -std=c11 -Wall -Wextra -Wno-strict-aliasing -Wno-char-subscripts -Wno-format-truncation -Wno-gnu-alignof-expression -fno-gnu89-inline -Wno-cast-function-type
CXX_FLAGS: -fexceptions -funwind-tables -fno-common -fopenmp -msse2 -std=c++11 -Wall -Wextra -Wno-strict-aliasing -Wno-char-subscripts -Wno-format-truncation -Wno-invalid-offsetof -Wno-gnu-alignof-expression -Wno-cast-function-type
Steps to reproduce
Run tarantool. Execute the following script:
box.cfg{}
test1 = box.schema.create_space("test1")
test1:format({{ name = "id", type = "unsigned" }})
test1:create_index("primary")
test1:insert({1})
test1:insert({2})
test1:insert({3})
Now run the following query:
tarantool> box.execute([[select "id" from "test1"]])
---
- metadata:
- name: id
type: unsigned
rows:
- [1]
- [2]
- [3]
...
Note the type of the column. It's 'unsigned'. Everything is OK so far. Run this:
tarantool> box.execute([[select sum("id") from "test1";]])
---
- metadata:
- name: COLUMN_1
type: integer
rows:
- [6]
...
The type of the column is 'integer' now. It makes me a bit nervous already, but still is not critical. Finally run this:
tarantool> box.execute([[
> select sum("id")
> from (select "id" from "test1");
> ]])
---
- metadata:
- name: COLUMN_1
type: decimal
rows:
- [6]
...
This is a real crash obviously!
- Why is the type of the column 'decimal' now?
- What's worse, the values of the column are not really decimal, they have type 'number'!
tarantool> type(box.execute([[
select sum("id")
from (select "id" from "test1");
]]).rows[1][1])
---
- number
...
Actual behavior
tarantool> box.execute([[select sum("id") from "test1";]])
---
- metadata:
- name: COLUMN_1
type: integer
rows:
- [6]
...
tarantool> box.execute([[
> select sum("id")
> from (select "id" from "test1");
> ]])
---
- metadata:
- name: COLUMN_1
type: decimal
rows:
- [6]
...
Expected behavior
tarantool> box.execute([[select sum("id") from "test1";]])
---
- metadata:
- name: COLUMN_1
type: unsigned
rows:
- [6]
...
tarantool> box.execute([[
> select sum("id")
> from (select "id" from "test1");
> ]])
---
- metadata:
- name: COLUMN_1
type: unsigned
rows:
- [6]
...
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.