Skip to content

Vectorized aggregation: assertion 'is_vector_type' on GROUP BY of a varchar segmentby column over compressed chunks (2.25.0, PG18) #9947

Description

@jamesfredley

What type of bug is this?

Crash / unexpected error

What subsystems and features are affected?

Compression (columnstore), Query planner / Vectorized aggregation

What happened?

A GROUP BY on a character varying (varchar) segmentby column over compressed chunks fails with an assertion-style error when vectorized aggregation is enabled (the default):

ERROR:  a variable with non-vectorizable type character varying is marked as vectorized
DETAIL:  Assertion 'is_vector_type(var->vartype)' failed.

The same query succeeds when:

  • the segmentby column is declared text instead of varchar, or
  • timescaledb.enable_vectorized_aggregation = off is set.

So the vectorized grouping path appears to accept a varchar (character varying, which carries a typmod) segmentby column as a grouping key, then asserts because character varying is not a vectorizable type. text is handled correctly.

This is the same class of vectorized-aggregation planning bug as #7410 / PR #7415 (Assertion 'value_column_description != NULL'), which was fixed in 2.18 with the same enable_vectorized_aggregation = off workaround - but that fix does not cover this varchar-segmentby case in 2.25.0.

How can we reproduce the bug?

PostgreSQL 18.1, TimescaleDB 2.25.0. Minimal, self-contained:

CREATE TABLE vtest (ts timestamptz NOT NULL, tenant varchar(255), visitor varchar(255), val int);
SELECT create_hypertable('vtest', 'ts', chunk_time_interval => INTERVAL '1 day');
ALTER TABLE vtest SET (
    timescaledb.compress,
    timescaledb.compress_segmentby = 'tenant, visitor',
    timescaledb.compress_orderby = 'ts DESC'
);

INSERT INTO vtest
SELECT '2024-01-01'::timestamptz + (g % 3) * INTERVAL '1 day',
       (ARRAY['t1','t2','t3'])[1 + g % 3],
       'v' || (g % 50),
       g
FROM generate_series(1, 5000) g;

SELECT count(compress_chunk(c)) FROM show_chunks('vtest') c;

-- FAILS (vectorized aggregation on, the default):
SELECT tenant, count(*) FROM vtest GROUP BY tenant ORDER BY tenant;
-- ERROR: a variable with non-vectorizable type character varying is marked as vectorized
-- DETAIL: Assertion 'is_vector_type(var->vartype)' failed.

-- WORKS:
SET timescaledb.enable_vectorized_aggregation = off;
SELECT tenant, count(*) FROM vtest GROUP BY tenant ORDER BY tenant;

Notes:

  • TimescaleDB emits the "column type character varying ... does not follow best practices, use TEXT instead" warning at ALTER TABLE ... compress_segmentby, but still allows it - and the resulting GROUP BY then crashes rather than degrading gracefully or refusing at definition time.
  • Declaring the same columns as text (instead of varchar) makes the failing query succeed with vectorized aggregation on. So the trigger is specifically the character varying type of the segmentby column, not the multi-column segmentby or the prefix grouping.

Expected behavior

SELECT tenant, count(*) ... GROUP BY tenant over compressed chunks should return correct results regardless of whether the segmentby column is text or varchar - either by handling varchar in the vectorized grouping path, or by transparently falling back to non-vectorized aggregation instead of raising an assertion error.

TimescaleDB version affected

2.25.0

PostgreSQL version used

18.1

What operating system did you use?

Windows (also relevant: this is the standard install, not a debug build)

What installation method did you use?

(installer / package)

What platform did you run on?

On prem/Self-hosted

Relevant log output and stack trace

ERROR:  a variable with non-vectorizable type character varying is marked as vectorized
DETAIL:  Assertion 'is_vector_type(var->vartype)' failed.

How can we reproduce the bug?

See the minimal script above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions