Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

backend: support stored generated columns in local/importer backends #505

Merged
merged 3 commits into from
Dec 5, 2020

Conversation

kennytm
Copy link
Collaborator

@kennytm kennytm commented Dec 2, 2020

What problem does this PR solve?

Properly support stored generated columns in local/importer backends.

Unlike virtual generated columns, the value of stored generated columns are saved into the KV entries. This is computed before AddRecord(). Therefore, before this PR, all stored generated columns imported using local or importer backends become NULL.

What is changed and how it works?

We now fill in the stored generated columns by evaluating their expressions.

Check List

Tests

  • Integration test

Side effects

  • Increased code complexity

Related changes

Release notes

Fixed: In local and importer backends, stored generated columns are properly filled in instead of being NULL.

@kennytm kennytm added the status/PTAL This PR is ready for review. Add this label back after committing new changes label Dec 2, 2020
@kennytm kennytm force-pushed the kennytm/stored-generated-expressions branch from f212eff to 8dad811 Compare December 2, 2020 18:17
@@ -197,6 +197,7 @@ func newSession(options *SessionOptions) *session {
vars.StmtCtx.TimeZone = vars.Location()
vars.SetSystemVar("timestamp", strconv.FormatInt(options.Timestamp, 10))
vars.SetSystemVar(variable.TiDBRowFormatVersion, options.RowFormatVersion)
vars.SetSystemVar(variable.MaxAllowedPacket, strconv.FormatUint(variable.MaxOfMaxAllowedPacket, 10))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(the RPAD() function relies on @@max_allowed_packet)

@glorv
Copy link
Contributor

glorv commented Dec 3, 2020

LGTM

@glorv glorv added status/LGT1 One reviewer already commented LGTM (LGTM1) and removed status/PTAL This PR is ready for review. Add this label back after committing new changes labels Dec 3, 2020
return nil, logEvalGenExprFailed(logger, row, col, err)
}
mutRow.SetDatum(gc.index, value)
record[gc.index] = value
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM

Why need these two setter both🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@lance6716 Setting the MutRow is needed for cascading generated columns (think c as b+1 & a as b+1, when calculating c we need to calculate b first).
Setting the record is for inserting the result into the table.
MutRow and []types.Datum can't be cheaply converted between each other so we keep both of them.

@lance6716 lance6716 added status/LGT2 Two reviewers already commented LGTM, ready for merge (LGTM2) and removed status/LGT1 One reviewer already commented LGTM (LGTM1) labels Dec 5, 2020
@kennytm kennytm merged commit a7fb063 into master Dec 5, 2020
@kennytm kennytm deleted the kennytm/stored-generated-expressions branch December 5, 2020 11:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status/LGT2 Two reviewers already commented LGTM, ready for merge (LGTM2)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants