Skip to content

text field convert to json result data query inconsistency #10845

@yongman

Description

@yongman

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE event_log1 (
  event_timestamp bigint NOT NULL,
  approximate_arrival_timestamp datetime NOT NULL,
  action_params text DEFAULT NULL -- text type
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T! SHARD_ROW_ID_BITS=4 PRE_SPLIT_REGIONS=2 */
PARTITION BY RANGE COLUMNS(approximate_arrival_timestamp)
(PARTITION p202603 VALUES LESS THAN ('2026-04-01 00:00:00'),
 PARTITION p202604 VALUES LESS THAN ('2026-05-01 00:00:00'),
 PARTITION p202605 VALUES LESS THAN ('2026-06-01 00:00:00'),
 PARTITION p202606 VALUES LESS THAN ('2026-07-01 00:00:00'));
INSERT INTO event_log1
  (event_timestamp,approximate_arrival_timestamp,action_params) VALUES
  (1747312496000,'2026-05-15 12:34:56','{"popup_id":"123"}'),
  (1747312556000,'2026-05-15 12:35:56','{"popup_id":"123"}'),
  (1747312616000,'2026-05-15 12:36:56','{"popup_id":"0"}'),
  (1747312676000,'2026-05-15 12:37:56','{"popup_id":"456"}'),
  (1747312736000,'2026-05-15 12:38:56','{"popup_id":"789"}');
ALTER TABLE event_log1 SET TIFLASH REPLICA 1;
CREATE TABLE event_log2 (
  event_timestamp bigint NOT NULL,
  approximate_arrival_timestamp datetime NOT NULL,
  action_params JSON DEFAULT NULL -- JSON type
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T! SHARD_ROW_ID_BITS=4 PRE_SPLIT_REGIONS=2 */
PARTITION BY RANGE COLUMNS(approximate_arrival_timestamp)
(PARTITION p202603 VALUES LESS THAN ('2026-04-01 00:00:00'),
 PARTITION p202604 VALUES LESS THAN ('2026-05-01 00:00:00'),
 PARTITION p202605 VALUES LESS THAN ('2026-06-01 00:00:00'),
 PARTITION p202606 VALUES LESS THAN ('2026-07-01 00:00:00'));
INSERT INTO event_log2
  (event_timestamp,approximate_arrival_timestamp,action_params) VALUES
  (1747312496000,'2026-05-15 12:34:56','{"popup_id":"123"}'),
  (1747312556000,'2026-05-15 12:35:56','{"popup_id":"123"}'),
  (1747312616000,'2026-05-15 12:36:56','{"popup_id":"0"}'),
  (1747312676000,'2026-05-15 12:37:56','{"popup_id":"456"}'),
  (1747312736000,'2026-05-15 12:38:56','{"popup_id":"789"}');
ALTER TABLE event_log2 SET TIFLASH REPLICA 1;

2. What did you expect to see? (Required)

Both query on event_log1 (with action_params is TEXT) and event_log2 (with action_params is JSON), the SQL below should be the same.

SET SESSION tidb_isolation_read_engines='tiflash';
SELECT 'tiflash',action_params,JSON_EXTRACT(action_params, '$.popup_id')
FROM test.event_log1
WHERE JSON_EXTRACT(action_params, '$.popup_id') is null;
+---------+---------------+-------------------------------------------+
| tiflash | action_params | JSON_EXTRACT(action_params, '$.popup_id') |
+---------+---------------+-------------------------------------------+
+---------+---------------+-------------------------------------------+

SET SESSION tidb_isolation_read_engines='tiflash';
SELECT 'tiflash',action_params,JSON_EXTRACT(action_params, '$.popup_id')
FROM test.event_log1
WHERE JSON_EXTRACT(action_params, '$.popup_id') is not null;
+---------+---------------------+-------------------------------------------+
| tiflash | action_params       | JSON_EXTRACT(action_params, '$.popup_id') |
+---------+---------------------+-------------------------------------------+
| tiflash | {"popup_id": "123"} | "123"                                     |
| tiflash | {"popup_id": "123"} | "123"                                     |
| tiflash | {"popup_id": "0"}   | "0"                                       |
| tiflash | {"popup_id": "456"} | "456"                                     |
| tiflash | {"popup_id": "789"} | "789"                                     |
+---------+---------------------+-------------------------------------------+
SET SESSION tidb_isolation_read_engines='tiflash';
SELECT 'tiflash',action_params,JSON_EXTRACT(action_params, '$.popup_id')
FROM test.event_log2
WHERE JSON_EXTRACT(action_params, '$.popup_id') is null;
+---------+---------------+-------------------------------------------+
| tiflash | action_params | JSON_EXTRACT(action_params, '$.popup_id') |
+---------+---------------+-------------------------------------------+
+---------+---------------+-------------------------------------------+

SET SESSION tidb_isolation_read_engines='tiflash';
SELECT 'tiflash',action_params,JSON_EXTRACT(action_params, '$.popup_id')
FROM test.event_log2
WHERE JSON_EXTRACT(action_params, '$.popup_id') is not null;
+---------+---------------------+-------------------------------------------+
| tiflash | action_params       | JSON_EXTRACT(action_params, '$.popup_id') |
+---------+---------------------+-------------------------------------------+
| tiflash | {"popup_id": "123"} | "123"                                     |
| tiflash | {"popup_id": "123"} | "123"                                     |
| tiflash | {"popup_id": "0"}   | "0"                                       |
| tiflash | {"popup_id": "456"} | "456"                                     |
| tiflash | {"popup_id": "789"} | "789"                                     |
+---------+---------------------+-------------------------------------------+

3. What did you see instead (Required)

when action_params is type 'TEXT', the query result is not expected

SET SESSION tidb_isolation_read_engines='tiflash';
SELECT 'tiflash',action_params,JSON_EXTRACT(action_params, '$.popup_id')
FROM test.event_log1
WHERE JSON_EXTRACT(action_params, '$.popup_id') is null;
+---------+--------------------+-------------------------------------------+
| tiflash | action_params      | JSON_EXTRACT(action_params, '$.popup_id') |
+---------+--------------------+-------------------------------------------+
| tiflash | {"popup_id":"123"} | "123"                                     |
| tiflash | {"popup_id":"123"} | "123"                                     |
| tiflash | {"popup_id":"0"}   | "0"                                       |
| tiflash | {"popup_id":"456"} | "456"                                     |
| tiflash | {"popup_id":"789"} | "789"                                     |
+---------+--------------------+-------------------------------------------+

SET SESSION tidb_isolation_read_engines='tiflash';
SELECT 'tiflash',action_params,JSON_EXTRACT(action_params, '$.popup_id')
FROM test.event_log1
WHERE JSON_EXTRACT(action_params, '$.popup_id') is not null;
+---------+---------------+-------------------------------------------+
| tiflash | action_params | JSON_EXTRACT(action_params, '$.popup_id') |
+---------+---------------+-------------------------------------------+
+---------+---------------+-------------------------------------------+

when action_params is type 'JSON', the query result is as expected

SET SESSION tidb_isolation_read_engines='tiflash';
SELECT 'tiflash',action_params,JSON_EXTRACT(action_params, '$.popup_id')
FROM test.event_log2
WHERE JSON_EXTRACT(action_params, '$.popup_id') is null;
+---------+---------------+-------------------------------------------+
| tiflash | action_params | JSON_EXTRACT(action_params, '$.popup_id') |
+---------+---------------+-------------------------------------------+
+---------+---------------+-------------------------------------------+

SET SESSION tidb_isolation_read_engines='tiflash';
SELECT 'tiflash',action_params,JSON_EXTRACT(action_params, '$.popup_id')
FROM test.event_log2
WHERE JSON_EXTRACT(action_params, '$.popup_id') is not null;
+---------+---------------------+-------------------------------------------+
| tiflash | action_params       | JSON_EXTRACT(action_params, '$.popup_id') |
+---------+---------------------+-------------------------------------------+
| tiflash | {"popup_id": "123"} | "123"                                     |
| tiflash | {"popup_id": "123"} | "123"                                     |
| tiflash | {"popup_id": "0"}   | "0"                                       |
| tiflash | {"popup_id": "456"} | "456"                                     |
| tiflash | {"popup_id": "789"} | "789"                                     |
+---------+---------------------+-------------------------------------------+

4. What is your TiFlash version? (Required)

Metadata

Metadata

Assignees

No one assigned

    Labels

    component/computenextgenIndicates that the Issue or PR belongs to the nextgen kernel architecture.severity/moderatetype/bugThe issue is confirmed as a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions