Skip to content

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

Closed as not planned

Description

@iamlinjunhong

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 port 26201; Go 1.27.1

Actual Behavior

LOAD DATA from a CSV file stores abc (3 characters) into a CHAR(0) / VARCHAR(0) column:

  • Under sql_mode='STRICT_TRANS_TABLES', the load succeeds instead of failing with Data too long.
  • Under sql_mode='', the load stores all characters instead of truncating to the empty string.

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

Expected Behavior

  • Zero is a declared CHAR/VARCHAR capacity, as already established for the Parquet path by fix(sql): enforce zero-width parquet text columns #29988.
  • Strict server CSV LOAD should reject a nonempty value with Data too long for column ....
  • Non-strict and LOCAL CSV LOAD should truncate the value to the empty string.

Steps to Reproduce

CREATE TABLE zc (id INT PRIMARY KEY, v CHAR(0));
-- file with content:  1,abc

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

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

Expected strict result: statement fails. Expected non-strict result: HEX(v)='', CHAR_LENGTH(v)=0.

Additional information

The CSV text conversion has the same boundary that PR #29988 fixed for Parquet: zero is treated as “unbounded” instead of as a declared capacity.

  • pkg/sql/colexec/external/external.go truncateLoadDataStringValue returns the value unchanged when width <= 0.
  • The strict CHAR/VARCHAR check a few lines later requires col.Typ.Width > 0, so CHAR(0) never reaches Data too long.

A direct unit regression now reproduces the failure:go test ./pkg/sql/colexec/external -run TestLoomCSVZeroWidthText -count=1

All strict/non-strict/LOCAL cases in that test persist abc; positive-width behavior is unchanged. The new test is pkg/sql/colexec/external/loom_test_zero_width_text_test.go (workspace only).

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. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    This report is now tracked together with #30457. The canonical issue retains explicit acceptance cases for the behavior described here. This is an administrative duplicate/consolidation closure only; the underlying defect is not claimed fixed. The original description and discussion remain available on this issue.

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