Skip to content

[Bug]: Hash window partition changes CHAR trailing-space partition membership #27952

Closed

Description

@iamlinjunhong

Summary

The cost-based HASH implementation for ordinary window partitions changes existing window results for CHAR keys containing trailing spaces. The legacy SORT path treats the byte-distinct values as separate partition keys, while the new hash path canonicalizes CHAR values by removing trailing spaces and merges them.

Reproduction

Environment:

  • Repository: matrixorigin/matrixone
  • Branch: m-27943
  • Commit: 3fc0fb239b56b66cef2c8e876e4096a4ca728234
  • Base: 33af6ae
  • Server: local MatrixOne v27943 on 127.0.0.1:6001
CREATE DATABASE m27943_char;
USE m27943_char;
CREATE TABLE t(id INT, ch CHAR(8), v INT);
-- Insert 12,000 rows. For each logical key K000..K007, insert 1,363 unpadded
-- rows and 137 rows with two trailing spaces; include v as a unique payload.
ANALYZE TABLE t;
SET SESSION agg_spill_mem=1073741824;
EXPLAIN ANALYZE
SELECT id, ch, COUNT(*) OVER (PARTITION BY ch) AS c FROM t;

With the large threshold, EXPLAIN selects Hash Partition. Both K000 and K000 receive count 1,500.

For the same data:

SET SESSION agg_spill_mem=1;
SELECT id, ch, COUNT(*) OVER (PARTITION BY ch) AS c FROM t;

The threshold forces the legacy SORT fallback. K000 receives 1,363 and K000 receives 137 (the corresponding counts are 1,363/137 for every key).

Expected

Changing the physical partition algorithm must not change window partition membership. HASH and SORT should use the same established equality relation, or CHAR should remain on SORT until the comparator and hash semantics are aligned.

Evidence

The difference is deterministic across repeated executions. The hash path uses canonicalVarlenaHashValue in pkg/common/hashmap/strhashmap.go, which strips trailing spaces for T_char; the existing window sort comparator in pkg/compare/strcompare.go compares raw bytes. The result is a user-visible change in COUNT, ranking, and aggregate window functions whenever a CHAR column has trailing-space variants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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