hasura / hasura/graphql-engine

Hasura generated WITH query name exceeding PostgreSQL max identifier length.

Open
#6,561 3 comments 6 reactions 0 assignees View on GitHub
support/needs-triage
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

Similar to #6410 this is an issue with the [max identifier length in PostgreSQL being 63 chars](https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS)
> The system uses no more than NAMEDATALEN-1 bytes of an identifier; longer names can be written in commands, but they will be truncated. By default, NAMEDATALEN is 64 so the maximum identifier length is 63 bytes.

But in this case, Hasura is generating the identifiers, and appending a string to the end of the data type name. We have some long data type names, in the case of this error, the data type name is 63 chars. 51 in the table, 11 in the schema, plus the joining `_`, in the query though, Hasura is generating the SQL string:
```sql
WITH really_long_data_type_that_is_already_63_characters_long_achooo__mutation_result_alias
-- 012345678901234567890123456789012345678901234567890123456789012 = 63 chars
-- 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345 = 86 chars
-- ^^^^^^^^^^^^^^^^^^^^^^^
-- WITH appended chars
```
(also `__all_columns_alias` is appended in another part of the query)

Running this generated query in Postgres client, yields 5 notices like `identifier really_long_data_type_that_is_already_63_characters_long_achooo__mutation_result_alias will be truncated to really_long_data_type_that_is_already_63_characters_long_achooo`

And the operation then fails with `WITH query name "really_long_data_type_that_is_already_63_characters_long_achooo" specified more than once`.

Hasura: v1.3.3

Contributor guide

Open the contributing guide

Research direction

The payload names no source file or test. Start by tracing the code that generates Hasura's PostgreSQL WITH query names, then reproduce the 63-character data type case described here. Done means generated identifiers stay within PostgreSQL's limit without causing duplicate WITH query names, including the other appended aliases.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.