Skip to content

catalog: Populate PostgreSQL type lengths - #39775

Merged
sjwiesman merged 1 commit into
MaterializeInc:mainfrom
sjwiesman:trino-compat
Oct 13, 2026
Merged

sjwiesman merged 1 commit into
MaterializeInc:mainfrom
sjwiesman:trino-compat

Conversation

@sjwiesman

@sjwiesman sjwiesman commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

pg_type.typlen and pg_attribute.attlen are always NULL in Materialize. pgjdbc derives DatabaseMetaData.getMaxColumnNameLength() and getMaxTableNameLength() from the typlen of name, so it reports -1 instead of 63. Trino's PostgreSQL connector treats a non-positive identifier limit as an error, which breaks join pushdown (and table creation) against Materialize.

Description

mz_internal.mz_type_pg_metadata gains a nullable typlen column, and pg_type reads typlen from it instead of NULL::int2. pg_attribute.attlen is derived from pg_type.typlen, so it is populated too.

The value comes from resolving the catalog type to its SqlScalarType and asking mz_pgrepr::Type for its length. That is the same value pgwire already sends as type_len in RowDescription, so the catalog and the wire protocol agree. Type::from_oid was not used because it does not know name, aclitem, _record, and a few other built-ins.

Types with no PostgreSQL counterpart keep a NULL typlen: pseudo-types (anyelement, ...), _record, and Materialize-only types such as uint2 and list. mz_type_pg_metadata describes the PostgreSQL view of a type, so inventing lengths for types PostgreSQL does not have would misreport.

Because mz_type_pg_metadata is a builtin table with a new column, it gets a replacement builtin schema migration.

Verification

  • test_compare_builtins_postgres now also asserts that every built-in type with a PostgreSQL counterpart reports the same typlen as PostgreSQL.
  • pg_catalog_attribute.slt checks typlen for a spread of fixed-length, variable-length, pseudo, and Materialize-only types, and attlen for table columns.
  • The Java smoketest asserts that pgjdbc reports 63 for the maximum column and table name lengths.
  • cockroach/orms.slt, catalog_server_explain.slt and mz_catalog_server_index_accounting.slt are updated for the populated attlen and the changed view definition.
  • Manually, Trino's PostgreSQL connector pushes joins down to Materialize with this change, and fails to do so without it.

Release notes

This release will report PostgreSQL type lengths in pg_type.typlen and pg_attribute.attlen, which lets JDBC-based tools such as Trino read identifier length limits correctly.

@sjwiesman
sjwiesman requested review from a team as code owners October 12, 2026 21:29
@sjwiesman
sjwiesman requested review from jdonelson and removed request for a team and jdonelson October 12, 2026 21:29

@antiguru antiguru left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, please update the PR body before merging.

@ggevay ggevay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@sjwiesman
sjwiesman merged commit 4bf36f3 into MaterializeInc:main Oct 13, 2026
93 checks passed
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.

3 participants