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

should fill index data after adding an index on a virtual generated column #11139

Closed
zz-jason opened this issue Jul 9, 2019 · 3 comments · Fixed by #11260
Closed

should fill index data after adding an index on a virtual generated column #11139

zz-jason opened this issue Jul 9, 2019 · 3 comments · Fixed by #11260
Assignees
Labels
type/bug This issue is a bug.

Comments

@zz-jason
Copy link
Member

zz-jason commented Jul 9, 2019

Bug Report

1. What did you do?

All the following operations are executed on a tidb-server built from #10802

drop table if exists t;
create table t(a bigint, b bigint as (a+1) virtual, c bigint as (b+1) virtual);
alter table t add index idx_b(b);
alter table t add index idx_c(c);
insert into t(a) values(1);
alter table t add column(d bigint as (c+1) virtual);

The query below can produce a correct result:

TiDB(root@127.0.0.1:test) > select * from t where d > 2;
+------+------+------+------+
| a    | b    | c    | d    |
+------+------+------+------+
|    1 |    2 |    3 |    4 |
+------+------+------+------+
1 row in set (0.00 sec)

Then create an index on the newly added column d:

alter table t add index idx_d(d);

And run the query again, the result is incorrect:

TiDB(root@127.0.0.1:test) > select * from t where d > 2;
Empty set (0.00 sec)

The execution plan now is changed to:

TiDB(root@127.0.0.1:test) > desc select * from t where d > 2;
+----------------------+-------+------+----------------------------------------------------------------------------------------------------------------------------------+
| id                   | count | task | operator info                                                                                                                    |
+----------------------+-------+------+----------------------------------------------------------------------------------------------------------------------------------+
| Projection_11        | 0.33  | root | test.t.a, cast(plus(test.t.a, 1)), cast(plus(cast(plus(test.t.a, 1)), 1)), cast(plus(cast(plus(cast(plus(test.t.a, 1)), 1)), 1)) |
| └─IndexLookUp_12     | 0.33  | root |                                                                                                                                  |
|   ├─IndexScan_9      | 0.33  | cop  | table:t, index:d, range:(2,+inf], keep order:false, stats:pseudo                                                                 |
|   └─TableScan_10     | 0.33  | cop  | table:t, keep order:false, stats:pseudo                                                                                          |
+----------------------+-------+------+----------------------------------------------------------------------------------------------------------------------------------+
4 rows in set (0.00 sec)

2. What did you expect to see?

produce the correct result

3. What did you see instead?

As I mentioned above, it produces no result.

4. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?

TiDB(root@127.0.0.1:test) > select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v3.0.0-rc.1-314-gca686bba7
Git Commit Hash: ca686bba759ea6127fae70746abba5437f6c7e42
Git Branch: pr/10802
UTC Build Time: 2019-07-09 02:44:55
GoVersion: go version go1.12.5 darwin/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false
1 row in set (0.00 sec)
@zz-jason zz-jason added the type/bug This issue is a bug. label Jul 9, 2019
@crazycs520
Copy link
Contributor

I will fix this today.

@zz-jason
Copy link
Member Author

zz-jason commented Jul 9, 2019

I think @tangenta is under investigating?

@crazycs520
Copy link
Contributor

@tangenta is busy doing another thing now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants