Skip to content

[Bug]: BIT value literals fail in logical operators despite numeric semantics #30930

Closed as not planned

Description

@Ariznawlll

Description

The supported bit-value literal b'1' is numerically 1 and is accepted as true by IF, but the same literal in AND fails at execution with invalid input: '\x01' is not a valid bool expression. b'0' AND 1 also fails. This is the literal/binary-byte conversion path, not the BIT column implicit-cast gap added to #30922.

Environment

  • Branch: official main
  • Commit: d4c37f4d8722dd91b80f5f5547940004bf1b293f
  • Deployment: isolated local MatrixOne cluster with two CN SQL endpoints; Connector/J 8.4 server-prepared/cursor control.
  • Reference: separately initialized MySQL Community Server 8.3.0 on a private Unix socket (no shared database or TCP listener).
  • Date: 2026-10-23

Steps to reproduce

SELECT IF(b'1', 1, 0), b'1'+0, CAST(b'1' AS UNSIGNED) AND 1;
-- 1, 1, 1 (normal controls)

SELECT b'1' AND 1;
-- ERROR 20301 (HY000): invalid input: '\x01' is not a valid bool expression

SELECT b'0' AND 1;
-- ERROR 20301 (HY000): invalid boolean-expression input

A server-prepared SELECT b'1' AND ? with ?=1 also fails with 20301. The same connection remains usable after the error.

Actual behavior

AND implicitly sends the bit literal's raw byte (0x01 or 0x00) to textual boolean parsing. The operation errors rather than returning a Boolean, even though IF and arithmetic on the same literal work and an explicit unsigned cast makes the AND result 1.

Expected behavior

Logical use of b'1' should return true and of b'0' false, consistently with MatrixOne's IF/numeric results and MySQL's bit-value-literal documentation. The isolated MySQL 8.3.0 reference returned 1 and 0 for these two AND expressions in the same SQL mode (defaults); IF(b'1',1,0) returned 1 in both engines.

Stability and controls

  • Reproducer: 3/3 independent fresh databases and fresh connections; ordinary SQL and server-prepared cursor query both return 20301.
  • Normal controls: IF(b'1',1,0)=1, b'1'+0=1, CAST(b'1' AS UNSIGNED) AND 1=1, BIT column WHERE b and IF(b,...) work.
  • Failure state: test table remains four rows and SELECT 1 succeeds after the errors.

Evidence

  • Exact 3/3 SQL/JDBC events: /private/tmp/mo-explore-run-20261023/prepared_121443/jdbc.jsonl.
  • Reproducer: /private/tmp/mo-explore-run-20261023/BitTruthCross.java.
  • MySQL 8.3.0 reference query returned version()=8.3.0, one_and=1, zero_and=0, if_one=1, text_control=0; the reference server used /private/tmp/mysql-bit-ref-nDCvuL/mysql.sock and no network listener.
  • Owned test objects were cleaned; no repository product code or test case was modified.

Code analysis

pkg/sql/plan/function/type_check.go admits implicit binary-string-to-BOOL conversion; pkg/container/types/tools.go:61-74 parses the resulting bytes with strconv.ParseBool / strconv.ParseFloat and rejects raw 0x01/0x00. The likely missing step is preserving the bit literal's numeric interpretation before this generic string parsing path. This is distinct from #30922's missing BIT column implicit-cast rule, and from #25245's ordinary nonnumeric text-string coercion ('abc'), whose desired numeric value is zero rather than bit value one.

Regression coverage

After the product fix, add bit literals 0/1/128 under AND, OR, NOT, IF, arithmetic, and binary prepared parameters, with BIT-column controls and error-recovery checks. No regression PR was added during this exploration.

Related

Activity

  1. added this to the MO-202610 milestone on Oct 23, 2026
  2. added
    kind/bug
    on Oct 23, 2026
  3. added theissue type on Oct 23, 2026
  4. XuPeng-SH commented on Oct 24, 2026

    @XuPeng-SH
    Contributor

    Tracking consolidated into #30931. The canonical issue now includes this report's independent scope and acceptance criteria. This is administrative consolidation, not a claim that the defect is fixed; the original reproduction and discussion are preserved here.

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

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions