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

sql: populate Oid on type upgrade #47234

Merged
merged 1 commit into from
Apr 9, 2020
Merged

Conversation

pbardea
Copy link
Contributor

@pbardea pbardea commented Apr 8, 2020

When types are unmarshalled, the types are upgraded and the Oid of the
internal type should be set. In 19.1, timestamps received an Oid and
they were populated by the default case in upgradeTypes. However,
a case to handle timestamps was added, but the Oids were no longer
set (as they didn't need to be anymore). However, this meant that
default case was not triggered anymore, so the Oid was no longer
set. This commit also sets the Oid in the timestamp case.

Fixes #44453.

Release note (bug fix): Restoring a backup from 2.1 to 20.1 with a
timestamp column would result in incomplete type data. This would
crash commands such as SHOW COLUMNS FROM <new_table>. This is now
fixed.

@pbardea pbardea requested review from jordanlewis and otan April 8, 2020 23:31
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@@ -1630,6 +1630,7 @@ func (t *T) upgradeType() error {
if t.InternalType.Precision > 0 {
t.InternalType.TimePrecisionIsSet = true
}
t.InternalType.Oid = familyToOid[t.Family()]
case IntervalFamily:
Copy link
Member

Choose a reason for hiding this comment

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

We also need this same thing for Intervals.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, I have a better idea. Can you instead remove the default case, and move it into an block after the switch statement, conditional on the Oid still being 0? That would protect us from future problems like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

should be able to add tests to this as well (there are upgradeType tests in types_test.go)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added tests that test an empty type with just the family always gets the correct Oid set - this was failing on timestamps, intervals and arrays before. I also added a test that the Oid for a BitFamily type with visible varbit was not set to the default family ID, but was set to the correct one.

@blathers-crl
Copy link

blathers-crl bot commented Apr 9, 2020

❌ The GitHub CI (Cockroach) build has failed on 4c9ae226.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. I am experimental - my owner is otan.

Copy link
Contributor

@otan otan left a comment

Choose a reason for hiding this comment

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

oops. thanks for catching this.

@@ -1630,6 +1630,7 @@ func (t *T) upgradeType() error {
if t.InternalType.Precision > 0 {
t.InternalType.TimePrecisionIsSet = true
}
t.InternalType.Oid = familyToOid[t.Family()]
case IntervalFamily:
Copy link
Contributor

Choose a reason for hiding this comment

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

should be able to add tests to this as well (there are upgradeType tests in types_test.go)

When types are unmarshalled, the types are upgraded and the Oid of the
internal type should be set. In 19.1, timestamps received an Oid and
they were populated by the default case in upgradeTypes. However,
a case to handle timestamps was added, but the Oids were no longer
set (as they didn't need to be anymore). However, this meant that
default case was not triggered anymore, so the Oid was no longer
set.

This commit moves the setting of the Oid from the default case to after
the switch statement and sets the Oid based on the type family if none
has been set yet.

Release note (bug fix): Restoring a backup from 2.1 to 20.1 with a
timestamp column would result in incomplete type data. This would
crash commands such as SHOW COLUMNS FROM <new_table>. This is now
fixed.
Copy link
Contributor

@otan otan left a comment

Choose a reason for hiding this comment

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

LGTM

@pbardea pbardea changed the title sql: populate timestamp Oid on unmarshall sql: populate Oid on type upgrade Apr 9, 2020
@pbardea
Copy link
Contributor Author

pbardea commented Apr 9, 2020

TFTRs!
bors r+

@craig
Copy link
Contributor

craig bot commented Apr 9, 2020

Build succeeded

@craig craig bot merged commit 0222b51 into cockroachdb:master Apr 9, 2020
@pbardea pbardea deleted the oid-timestamp branch April 27, 2020 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: restoring 2.1 backup into 20.1 cluster succeeds but seems to be in a bad state
4 participants