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

fix: SQL name resolving #5860

Merged
merged 1 commit into from Jul 27, 2023
Merged

fix: SQL name resolving #5860

merged 1 commit into from Jul 27, 2023

Conversation

aljazerzen
Copy link
Contributor

A result of tedious pg_dump debugging.
Tests on Postgres 15 were failing becuase they are using pg_dump 15,
which was producing the following statements that were
not produced by pg_dump 14:

CREATE TYPE edgedb."__SchemaAccessPolicy" (
    INTERNALLENGTH = variable,
    INPUT = array_in,
    OUTPUT = array_out,
    RECEIVE = array_recv,
    SEND = array_send,
    ANALYZE = array_typanalyze,
    ELEMENT = edgedb."_SchemaAccessPolicy",
    CATEGORY = 'A',
    ALIGNMENT = double,
    STORAGE = extended
);

Applying these dumps failed because type
edgedb."_SchemaAccessPolicy" did not exist.

After digging in pg_dump source code a bunch, trying to figure out
why these statements were showing up, I found a query similar to this:

select
  typname,
  (
    SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem
  ) = oid AS isarray
from pg_type;

After inspecting the results, I found that our resolver does not match
pg_type.typelem to the outer pg_type (as it should), but to the inner
pg_type, even though the inner pg_type has an alias which should make
the orignal name inaccessible.

So that's the bug. With an easy fix.
Turns out that when I implemented the resolver I did not know this detail,
becuase we even had a test for it.

A result of tedious pg_dump debugging.
Tests on Postgres 15 were failing becuase they are using pg_dump 15,
which was producing the following statements that were
not produced by pg_dump 14:

```sql
CREATE TYPE edgedb."__SchemaAccessPolicy" (
    INTERNALLENGTH = variable,
    INPUT = array_in,
    OUTPUT = array_out,
    RECEIVE = array_recv,
    SEND = array_send,
    ANALYZE = array_typanalyze,
    ELEMENT = edgedb."_SchemaAccessPolicy",
    CATEGORY = 'A',
    ALIGNMENT = double,
    STORAGE = extended
);
```

Applying these dumps failed because type
edgedb."_SchemaAccessPolicy" did not exist.

After digging in pg_dump source code a bunch, trying to figure out
why these statements were showing up, I found a query similar to this:

```sql
select
  typname,
  (
    SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem
  ) = oid AS isarray
from pg_type;
```

After inspecting the results, I found that our resolver does not match
`pg_type.typelem` to the outer `pg_type` (as it should), but to the inner
`pg_type`, even though the inner `pg_type` has an alias which should make
the orignal name inaccessible.

So that's the bug. With an easy fix.
Turns out that when I implemented the resolver I did not know this detail,
becuase we even had a test for it.
@aljazerzen
Copy link
Contributor Author

Ref #5697

@aljazerzen aljazerzen merged commit a48d7ba into master Jul 27, 2023
21 checks passed
@aljazerzen aljazerzen deleted the fix-pg-15 branch July 27, 2023 17:24
@msullivan
Copy link
Member

Nice detective work here

msullivan pushed a commit that referenced this pull request Sep 2, 2023
A result of tedious pg_dump debugging.
Tests on Postgres 15 were failing becuase they are using pg_dump 15,
which was producing the following statements that were
not produced by pg_dump 14:

```sql
CREATE TYPE edgedb."__SchemaAccessPolicy" (
    INTERNALLENGTH = variable,
    INPUT = array_in,
    OUTPUT = array_out,
    RECEIVE = array_recv,
    SEND = array_send,
    ANALYZE = array_typanalyze,
    ELEMENT = edgedb."_SchemaAccessPolicy",
    CATEGORY = 'A',
    ALIGNMENT = double,
    STORAGE = extended
);
```

Applying these dumps failed because type
edgedb."_SchemaAccessPolicy" did not exist.

After digging in pg_dump source code a bunch, trying to figure out
why these statements were showing up, I found a query similar to this:

```sql
select
  typname,
  (
    SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem
  ) = oid AS isarray
from pg_type;
```

After inspecting the results, I found that our resolver does not match
`pg_type.typelem` to the outer `pg_type` (as it should), but to the inner
`pg_type`, even though the inner `pg_type` has an alias which should make
the orignal name inaccessible.

So that's the bug. With an easy fix.
Turns out that when I implemented the resolver I did not know this detail,
becuase we even had a test for it.
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.

None yet

3 participants