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

release-20.1: sql: propagate opt types through renders #49353

Closed
wants to merge 1 commit into from

Conversation

rafiss
Copy link
Collaborator

@rafiss rafiss commented May 21, 2020

Backport 1/1 commits from #48619.

/cc @cockroachdb/release


Previously, folded expressions would sometimes get improperly typed,
because the optimizer type would be lost and replaced with the
ResolvedType of the folded expression. Datums can sometimes have
imprecise ResolvedTypes if they were created from expressions with
non-canonical types of a family.

Fixes #48563.

Release note (bug fix): improve accuracy of column types returned
from queries to improve PostgreSQL compatibility.

@rafiss rafiss requested a review from jordanlewis May 21, 2020 03:46
@rafiss rafiss requested a review from a team as a code owner May 21, 2020 03:46
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @jordanlewis)

@rafiss
Copy link
Collaborator Author

rafiss commented May 21, 2020

hmmm i think the test this was supposed to fix is not working:

Query {"String": "SELECT 'a'::\"char\" FROM a"}
----
            expected:
            {"Type":"RowDescription","Fields":[{"Name":"char","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":18,"DataTypeSize":1,"TypeModifier":-1,"Format":0}]}

            found:
            {"Type":"RowDescription","Fields":[{"Name":"char","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":25,"DataTypeSize":1,"TypeModifier":-1,"Format":0}]}

Previously, folded expressions would sometimes get improperly typed,
because the optimizer type would be lost and replaced with the
ResolvedType of the folded expression. Datums can sometimes have
imprecise ResolvedTypes if they were created from expressions with
non-canonical types of a family.

Fixes cockroachdb#48563.

Release note (bug fix): improve accuracy of column types returned
from queries to improve PostgreSQL compatibility.
@rafiss rafiss force-pushed the backport20.1-48619 branch from 07d5ade to c83f61f Compare May 21, 2020 21:46
@rafiss
Copy link
Collaborator Author

rafiss commented May 21, 2020

@RaduBerinde & @jordanlewis can you think of anything that might be missing here?

@jordanlewis
Copy link
Member

You would also need to backport @RaduBerinde's patch #48652

@rafiss
Copy link
Collaborator Author

rafiss commented May 21, 2020

That one has been backported here: #49331

@RaduBerinde
Copy link
Member

I don't get it either.. Without this PR we have

[email protected]:40541/defaultdb> explain (types) select a,b, ''::"char" from ab;
    tree    |    field    | description  |             columns              | ordering
------------+-------------+--------------+----------------------------------+-----------
            | distributed | true         |                                  |
            | vectorized  | false        |                                  |
  render    |             |              | (a int, b string, "char" string) |
   │        | render 0    | (a)[int]     |                                  |
   │        | render 1    | (b)[string]  |                                  |
   │        | render 2    | ('')[string] |                                  |
   └── scan |             |              | (a int, b string)                |
            | table       | ab@primary   |                                  |
            | spans       | FULL SCAN    |                                  |

And with this PR we have

[email protected]:39549/defaultdb> explain (types) select a,b, ''::"char" from ab;
    tree    |    field    | description  |             columns              | ordering
------------+-------------+--------------+----------------------------------+-----------
            | distributed | true         |                                  |
            | vectorized  | false        |                                  |
  render    |             |              | (a int, b string, "char" "char") |
   │        | render 0    | (a)[int]     |                                  |
   │        | render 1    | (b)[string]  |                                  |
   │        | render 2    | ('')[string] |                                  |
   └── scan |             |              | (a int, b string)                |
            | table       | ab@primary   |                                  |
            | spans       | FULL SCAN    |                                  |

So it looks like the top planNode has the correct type..

@RaduBerinde
Copy link
Member

Ah, lol, I think it's this map:

var resultOidMap = map[oid.Oid]oid.Oid{

@RaduBerinde
Copy link
Member

I think we need this: #44471

@RaduBerinde
Copy link
Member

I fell less and less comfortable making these changes in 20.1.x..

@rafiss
Copy link
Collaborator Author

rafiss commented May 21, 2020

Ah right I remember seeing that before... Thanks for the find. I'm fine abandoning this backport, if that's the vibe people are having.

Copy link
Contributor

@andy-kimball andy-kimball left a comment

Choose a reason for hiding this comment

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

Agreed that we shouldn't make a backwards-compat breaking change in a point release, unless we had an extraordinary reason to do so, agreement from all stakeholders, thorough documentation and education, etc.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @jordanlewis)

@rafiss
Copy link
Collaborator Author

rafiss commented May 22, 2020

we shouldn't make a backwards-compat breaking change in a point release...

Agreed. This was initially intended to be a small bugfix (filling in missing data), but now it's become something more than that.

Closing this.

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.

5 participants