Skip to content

[Bug]: LOAD DATA stores nonempty values in CHAR(0) and VARCHAR(0) columns #30457

Open

Description

@iamlinjunhong

Consolidated tracking scope

Track the duplicate report for LOAD DATA accepting nonempty input into zero-width character columns. The linked reports are retained as separate reproductions where they exercise different code paths. Closing a linked issue is an administrative consolidation only; no fix is claimed here.

Acceptance criteria

  • In strict mode, loading a nonempty value into CHAR(0)/VARCHAR(0) reports a data-too-long error.
  • In non-strict mode, apply the documented truncation behavior and warning consistently for server-side and LOCAL loads.
  • Retain the exact reproduction and commit evidence from both linked reports.

Included reports

  • #30460 — original report and discussion remain on that issue.

Original canonical report (preserved verbatim)

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

8669eed

Other Environment Information

  • Hardware parameters: Apple silicon (arm64), 10 cores
  • OS type: macOS 15.7
  • Others: standalone mo-service built from the workspace, MySQL protocol on port 26201, Go 1.27.1

Actual Behavior

CSV LOAD DATA stores the three-character value abc into a CHAR(0) or VARCHAR(0) column.

  • With sql_mode='STRICT_TRANS_TABLES', the server-side load succeeds instead of failing with Data too long.
  • With sql_mode='', the load persists all three characters instead of truncating to the empty string.
  • The same payload reaches the vector unchanged in serial, parallel and LOCAL paths.

The equivalent INSERT path honors the declared width: strict INSERT fails, and non-strict INSERT stores the empty string.

Expected Behavior

CHAR(0) and VARCHAR(0) are declared capacities, not unbounded text metadata. Zero-width semantics were already established for the Parquet path in issue #29811 and PR #29988.

  • Strict server CSV LOAD should reject a nonempty value with Data too long for column ....
  • Non-strict CSV LOAD and LOCAL CSV LOAD should truncate the value to the empty string, matching the INSERT assignment path.

Steps to Reproduce

Create a CSV file (zerow.csv) containing 1,abc followed by one newline, then run:

CREATE TABLE zc (id INT PRIMARY KEY, v CHAR(0));

SET sql_mode = 'STRICT_TRANS_TABLES';
LOAD DATA INFILE '/tmp/zerow.csv' INTO TABLE zc
  FIELDS TERMINATED BY ',' LINES TERMINATED BY '
';
SELECT id, HEX(v), CHAR_LENGTH(v) FROM zc;

TRUNCATE TABLE zc;
SET sql_mode = '';
LOAD DATA INFILE '/tmp/zerow.csv' INTO TABLE zc
  FIELDS TERMINATED BY ',' LINES TERMINATED BY '
';
SELECT id, HEX(v), CHAR_LENGTH(v) FROM zc;

SET sql_mode = 'STRICT_TRANS_TABLES';
INSERT INTO zc VALUES (2, 'x');
SET sql_mode = '';
INSERT INTO zc VALUES (3, 'somelong');

Expected: the first LOAD fails in strict mode; the non-strict LOAD stores an empty string and reports HEX(v)='', CHAR_LENGTH(v)=0. INSERT comparison: strict INSERT errors, non-strict INSERT stores the empty string.

Additional information

Root cause is the same zero-width boundary class that PR #29988 fixed for Parquet:

  • truncateLoadDataStringValue (pkg/sql/colexec/external/external.go:1351) returns the input unchanged when width <= 0.
  • The strict CHAR/VARCHAR guard (external.go:1688) requires col.Typ.Width > 0, so CHAR(0) never raises Data too long.

A new workspace regression test reproduces all seven variants: go test ./pkg/sql/colexec/external -run TestLoomCSVZeroWidthText -count=1. The test currently fails because every variant persists abc; positive-width behavior is unchanged. The test file is pkg/sql/colexec/external/loom_test_zero_width_text_test.go.

Found by Loom bug hunt (module: custom-a9872c7d6e; tests: unit, white-box, end-to-end)

Activity

  1. added
    kind/bug
    on Oct 17, 2026
  2. changed the title [-][Bug]: LOAD DATA persists nonempty values in CHAR(0) and VARCHAR(0) columns[/-] [+][Bug]: LOAD DATA stores nonempty values in CHAR(0) and VARCHAR(0) columns[/+] on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions