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: Arrays store wrong encoding type for DATE #19942

Closed
solongordon opened this issue Nov 9, 2017 · 4 comments
Closed

sql: Arrays store wrong encoding type for DATE #19942

solongordon opened this issue Nov 9, 2017 · 4 comments
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
Milestone

Comments

@solongordon
Copy link
Contributor

When arrays are encoded, we store the elements' encoding type in the array header. We're currently storing the wrong type for DATE arrays: encoding.Time (see sql/sqlbase/table.go#L1786) rather than encoding.Int (see sql/sqlbase/table.go#L1823).

Per @justinj, these header values aren't yet used for anything but may be in the future. This is trivial to fix, but it will create a potentially confusing discrepancy between values that were persisted before and after the fix.

@knz for his thoughts

@solongordon solongordon added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Nov 9, 2017
@knz knz added this to the 1.2 milestone Nov 9, 2017
@knz
Copy link
Contributor

knz commented Nov 9, 2017

The kosher way to do this is to create a cluster migration function that looks at all the table schemas currently defined, and for each one that actually uses ARRAY[DATE] launch a column rewrite.

I would be surprised however if people have been storing date arrays already since 1.1 was launched. @bdarnell thoughts?

@bdarnell
Copy link
Contributor

bdarnell commented Nov 9, 2017

I agree that date arrays don't seem like an especially likely thing, but do any of the metrics we collect tell us about whether people are doing this?

In any case, if we don't have any concrete plans to use these tags then we don't have to do anything right away - we could wait until we have a specific need before writing the implementation. (and in the meantime, we start writing the correct tag and maybe collect more metrics about whether this type is being used)

@solongordon
Copy link
Contributor Author

As far as I can see we don't collect any metrics along these lines. And if we started collecting them now, it still couldn't tell us definitively that no one is using date arrays since not everyone has metrics reporting enabled.

I agree it seems unlikely anyone is using date arrays at this point, so I'm inclined to just start writing the correct tag and add a warning comment in the code that there's a slim possibility there are incorrect headers out there. Let me know if that sounds reasonable.

solongordon added a commit to solongordon/cockroach that referenced this issue Dec 18, 2017
When we encode arrays, we were storing the wrong encoding type for
dates (encoding.Time rather than encoding.Int). This is now fixed.

This hasn't caused any problems so far since we don't use the
`elementType` header value for anything. If we start using it in the
future, there's a slim possibility there are persisted date arrays out
there with the incorrect value, in which case we would need some special
handling to detect and handle that scenario.

Refers cockroachdb#19942

Release note: None
@solongordon
Copy link
Contributor Author

I'm closing this since we're now writing the correct tag, but feel free to reopen if anyone feels we should do more work w.r.t. metrics collection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
Projects
None yet
Development

No branches or pull requests

3 participants