dolt icon indicating copy to clipboard operation
dolt copied to clipboard

Incorrect results for virtual column in `WHERE` or `ORDER BY`

Open nicktobey opened this issue 1 year ago • 0 comments

Example 1:

create table test(pk int primary key, j int, value int as (pk*pk));
insert into test(pk, j) values (-1, 1), (2, 1), (-3, 1);
select value from test order by value;

Expected output:

+-------+
| value |
+-------+
| 1     |
| 4     |
| 9     |
+-------+

Actual output:

+-------+
| value |
+-------+
| NULL  |
| NULL  |
| NULL  |
+-------+

Example 2:

create table test(pk int primary key, j int, k int, value int as (pk*pk));
insert into test(pk, j) values (-1, 1, 2), (2, 1, 2), (-3, 1, 2);
select value from test order by value;

Expected output:

+-------+
| value |
+-------+
| 1     |
| 4     |
| 9     |
+-------+

Actual output: unable to find field with index 2 in row of 2 columns

In both cases, columns j and k are unused, but affect the outcome. If there are no non-virtual value columns, the query behaves correctly. Adding a second virtual column causes queries on both virtual columns to behave correctly.

nicktobey avatar Sep 04 '24 19:09 nicktobey