unique key查询不出来数据

Viewed 39
mysql> select @@version_comment;
+----------------------------------------+
| @@version_comment                      |
+----------------------------------------+
| Doris version doris-2.1.8-1-834d802457 |
+----------------------------------------+
1 row in set (0.04 sec)

有一张表结构如下:

CREATE TABLE `rm_vehicle_alarm_info2` (
  `arm_time_start` datetime NOT NULL COMMENT "开始时间",
  `vehicle_id` bigint NOT NULL COMMENT "ID",
  `arm_type` varchar(128) NOT NULL COMMENT "类型",
  `arm_source` int NOT NULL COMMENT "来源"
) ENGINE=OLAP
UNIQUE KEY(`arm_time_start`, `vehicle_id`, `arm_type`, `arm_source`)
COMMENT '报警表'
AUTO PARTITION BY RANGE (date_trunc(`arm_time_start`, 'month'))()
DISTRIBUTED BY HASH(`arm_time_start`, `vehicle_id`) BUCKETS AUTO
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"min_load_replica_num" = "-1",
"is_being_synced" = "false",
"storage_medium" = "hdd",
"storage_format" = "V2",
"inverted_index_storage_format" = "V1",
"enable_unique_key_merge_on_write" = "true",
"light_schema_change" = "true",
"disable_auto_compaction" = "false",
"enable_single_replica_compaction" = "false",
"group_commit_interval_ms" = "10000",
"group_commit_data_bytes" = "134217728",
"enable_mow_light_delete" = "false"
);;

现在创建一张tmp_x1表, 并且导入数据:

mysql> select count(*) from rm_vehicle_alarm_info2;
+----------+
| count(*) |
+----------+
|   301862 |
+----------+
1 row in set (0.03 sec)
  
mysql> create table tmp_x1 like rm_vehicle_alarm_info2;
Query OK, 0 rows affected (0.08 sec)

mysql> insert into tmp_x1 select * from rm_vehicle_alarm_info2;
Query OK, 301862 rows affected (0.85 sec)
{'label':'label_27aa1bf6ab944a8_9a6c8516f772882c', 'status':'VISIBLE', 'txnId':'345260'}

mysql> select count() from tmp_x1;
+----------+
| count(*) |
+----------+
|   301669 |
+----------+
1 row in set (0.04 sec)
  1. tmp_x1的数据量和rm_vehicle_alarm_info2不一样.

现在在rm_vehicle_alarm_info2有如下数据:

mysql> select
    ->  arm_time_start,vehicle_id,arm_type,arm_source
    -> from rm_vehicle_alarm_info2
    -> where arm_time_start='2025-03-25 15:27:58' 
    ->  and arm_type='firingAlarm' and arm_source=0;
+---------------------+---------------------+-------------+------------+
| arm_time_start      | vehicle_id          | arm_type    | arm_source |
+---------------------+---------------------+-------------+------------+
| 2025-03-25 15:27:58 | 1862101637583077378 | firingAlarm |          0 |
| 2025-03-25 15:27:58 | 1863856249893814273 | firingAlarm |          0 |
+---------------------+---------------------+-------------+------------+
2 rows in set (0.04 sec)

现在如果加上条件vehicle_id=1863856249893814273就查询不出来数据.
但是vehicle_id=1862101637583077378却有数据:

-- 1863856249893814273查询不处理
mysql> select 
    ->  arm_time_start,vehicle_id,arm_type,arm_source
    -> from 
    ->  rm_vehicle_alarm_info2
    -> where
    ->  arm_time_start='2025-03-25 15:27:58'
    -> and arm_type='firingAlarm'
    -> and arm_source=0
    -> and vehicle_id=1863856249893814273;
Empty set

-- 1862101637583077378 可以查询
mysql> select 
    ->  arm_time_start,vehicle_id,arm_type,arm_source
    -> from
    ->  rm_vehicle_alarm_info2
    -> where
    ->    arm_time_start='2025-03-25 15:27:58'
    ->  and arm_type='firingAlarm'
    ->  and arm_source=0
    ->  and vehicle_id=1862101637583077378;
+---------------------+---------------------+-------------+------------+
| arm_time_start      | vehicle_id          | arm_type    | arm_source |
+---------------------+---------------------+-------------+------------+
| 2025-03-25 15:27:58 | 1862101637583077378 | firingAlarm |          0 |
+---------------------+---------------------+-------------+------------+
1 row in set (0.05 sec)

查询tmp_x1表是正常的:

mysql> select arm_time_start,vehicle_id,arm_type,arm_source from tmp_x1 where arm_time_start='2025-03-25 15:27:58' and arm_type='firingAlarm' and arm_source=0;
+---------------------+---------------------+-------------+------------+
| arm_time_start      | vehicle_id          | arm_type    | arm_source |
+---------------------+---------------------+-------------+------------+
| 2025-03-25 15:27:58 | 1863856249893814273 | firingAlarm |          0 |
| 2025-03-25 15:27:58 | 1862101637583077378 | firingAlarm |          0 |
+---------------------+---------------------+-------------+------------+
2 rows in set (0.05 sec)

mysql> select arm_time_start,vehicle_id,arm_type,arm_source from tmp_x1 where arm_time_start='2025-03-25 15:27:58' and arm_type='firingAlarm' and arm_source=0 and vehicle_id=1863856249893814273;
+---------------------+---------------------+-------------+------------+
| arm_time_start      | vehicle_id          | arm_type    | arm_source |
+---------------------+---------------------+-------------+------------+
| 2025-03-25 15:27:58 | 1863856249893814273 | firingAlarm |          0 |
+---------------------+---------------------+-------------+------------+
1 row in set (0.04 sec)

mysql> select arm_time_start,vehicle_id,arm_type,arm_source from tmp_x1 where arm_time_start='2025-03-25 15:27:58' and arm_type='firingAlarm' and arm_source=0 and vehicle_id=1862101637583077378;
+---------------------+---------------------+-------------+------------+
| arm_time_start      | vehicle_id          | arm_type    | arm_source |
+---------------------+---------------------+-------------+------------+
| 2025-03-25 15:27:58 | 1862101637583077378 | firingAlarm |          0 |
+---------------------+---------------------+-------------+------------+
1 row in set (0.04 sec)

请问这是什么原因造成的?
是否能修复, 怎么修复?
还有这个这个表的分区和桶是否合理?

1 Answers

具体原因可能需要进一步排查,您方便加我主页微信我们一起排查下这个问题的。

我本地没能复现:
image.png