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

tables: basic support for hidden column #13908

Merged
merged 28 commits into from
Dec 17, 2019

Conversation

wjhuang2016
Copy link
Member

@wjhuang2016 wjhuang2016 commented Dec 4, 2019

What problem does this PR solve?

Expression index is based on hidden column.
This PR will basicly support hidden column(insert and other functions will be supported in next few PRs):

  1. Hidden column can't be selected.
  2. Hidden column can't be updated or used as update condition.
  3. Hidden column can't be used as delete condition.
  4. Hidden column can't be drop by ALTER TABLE DROP COLUMN statement.
  5. SHOW CREATE TABLE statement wouldn't display hidden columns.

What is changed and how it works?

  1. Add a method VisibleCols for interface table which will ignore hidden column and replace it with Cols in buildDatasourece. Then the hidden columns will not display in plan.schema, and can not be selected, even in order by, group by statement.
  2. (1) Since hidden column is used only by generate column, we check that if the generate column is hidden and be modified. If it is, raise an error.
    (2) For where and order by clause in update statement, we can't skip hidden column in writableCols, because we need to fill the assignment and do the update, which need the column infomation of the hidden column. So we skip the hidden column in toColumn of expression_rewriter.
  3. After 1 is done, hidden column can't be used as delete condition.
  4. Replace Cols with VisibleCols in DropColumn, then we can't drop the hidden column.
  5. After read the public columns by tableInfo.Cols(Not the Cols mention before) , skip it if it is a hidden column.

Check List

Tests

  • Unit test ( Contained in Integration test)
  • Integration test

Code changes

  • Has exported variable/fields change

Side effects

  • Possible performance regression
  • Increased code complexity
  • Breaking backward compatibility

Related changes

Release note

@wjhuang2016 wjhuang2016 requested a review from a team as a code owner December 4, 2019 12:16
@ghost ghost requested review from wshwsh12 and XuHuaiyu and removed request for a team December 4, 2019 12:16
@wjhuang2016
Copy link
Member Author

/run-all-tests

@zimulala zimulala self-requested a review December 5, 2019 02:42
table/tables/tables.go Show resolved Hide resolved
expression/integration_test.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Dec 5, 2019

Codecov Report

Merging #13908 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #13908   +/-   ##
===========================================
  Coverage   80.3975%   80.3975%           
===========================================
  Files           483        483           
  Lines        122449     122449           
===========================================
  Hits          98446      98446           
  Misses        16244      16244           
  Partials       7759       7759

table/tables/tables_test.go Show resolved Hide resolved
table/tables/tables_test.go Show resolved Hide resolved
table/tables/tables_test.go Outdated Show resolved Hide resolved
@wjhuang2016 wjhuang2016 force-pushed the hidden_for_select branch 2 times, most recently from 0f2c2d5 to 5e7217a Compare December 5, 2019 06:05
@wjhuang2016
Copy link
Member Author

/run-all-tests

1 similar comment
@wjhuang2016
Copy link
Member Author

/run-all-tests

@wjhuang2016
Copy link
Member Author

/run-all-tests

)

func (t *TableCommon) getCols(mode getColsMode) []*table.Column {
Columns := make([]*table.Column, 0, len(t.Columns))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Columns := make([]*table.Column, 0, len(t.Columns))
columns := make([]*table.Column, 0, len(t.Columns))

@@ -201,6 +201,7 @@ type Column struct {
VirtualExpr Expression

OrigName string
Hidden bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Hidden/IsHidden/

table/tables/tables.go Show resolved Hide resolved
table/tables/tables_test.go Show resolved Hide resolved
table/tables/tables_test.go Show resolved Hide resolved
executor/show.go Show resolved Hide resolved
table/tables/tables_test.go Outdated Show resolved Hide resolved
table/tables/tables_test.go Outdated Show resolved Hide resolved
@Deardrops
Copy link
Contributor

LGTM

@zimulala zimulala added component/DDL-need-LGT3 status/LGT1 Indicates that a PR has LGTM 1. labels Dec 11, 2019
for _, col := range t.Columns {
if col.State != model.StatePublic {
continue
}
publicColumns[col.Offset] = col
if maxOffset < col.Offset {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove these codes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous code imply that public column always before non-public column, and set the maxOffset to the last public column. When we intro hidden column, we can't guarantee the visible columns are continuous.

@@ -2373,7 +2373,7 @@ func (d *ddl) DropColumn(ctx sessionctx.Context, ti ast.Ident, spec *ast.AlterTa

// Check whether dropped column has existed.
colName := spec.OldColumnName.Name
col := table.FindCol(t.Cols(), colName.L)
col := table.FindCol(t.VisibleCols(), colName.L)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't drop hide columns. Could we do modify column operation to hide columns?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't modify the hidden column in theory, I will disable this operation in next PR

@sre-bot
Copy link
Contributor

sre-bot commented Dec 14, 2019

@sre-bot
Copy link
Contributor

sre-bot commented Dec 16, 2019

@djshow832
Copy link
Contributor

LGTM

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zimulala zimulala added status/LGT3 The PR has already had 3 LGTM. status/can-merge Indicates a PR has been approved by a committer. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Dec 17, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Dec 17, 2019

/run-all-tests

@sre-bot sre-bot merged commit 42adca9 into pingcap:master Dec 17, 2019
Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice done.

XiaTianliang pushed a commit to XiaTianliang/tidb that referenced this pull request Dec 21, 2019
@you06 you06 added the sig/sql-infra SIG: SQL Infra label Mar 4, 2020
@wjhuang2016 wjhuang2016 deleted the hidden_for_select branch November 17, 2022 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/sql-infra SIG: SQL Infra status/can-merge Indicates a PR has been approved by a committer. status/LGT3 The PR has already had 3 LGTM. type/new-feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants