Skip to content

Replace the JSON_VALID workaround with general short-circuit evaluation #11086

Description

@ChangRui-Ryan

Enhancement

#11036 fixed queries combining JSON_VALID with JSON operations in filter conditions. It detects a preceding JSON_VALID guard and allows the matching string-to-JSON cast to substitute JSON null for invalid input, so those rows can later be filtered out.

This is a targeted workaround rather than short-circuit evaluation: the guarded expression subtree still executes. Its scope is limited to recognized filter patterns, leaving cases such as projection expressions, OR conditions, and invalid dynamic JSON paths uncovered.

For example:

SELECT id FROM t
WHERE JSON_VALID(doc)
  AND JSON_EXTRACT(doc, json_path) IS NOT NULL;

If a row contains both invalid JSON and an invalid JSON path, tolerating the JSON cast error is insufficient: subsequent path evaluation can still fail. When JSON_VALID(doc) is false, the entire right-hand expression should be skipped for that row.

Replace this workaround with general short-circuit evaluation for AND, OR, and two_value_and, adapting ClickHouse's deferred expression evaluation approach to TiFlash. Support filters and projections, preserve TiDB NULL semantics, and retain errors from expressions that must execute.

Evaluation should follow the expression order supplied by TiDB.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/enhancementThe issue or PR belongs to an enhancement.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions