Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: tidb查询数据混乱
[TiDB Usage Environment] Test
[TiDB Version] 5.3
[Encountered Problem]
The composite primary key of this table is item_id and erpsource. When querying by delivery_id, two records with delivery_id=4025931 are returned, and these two records have the same composite primary key values!
SELECT * from erp_sdb_wms_delivery_items where delivery_id=4025931
When querying by item_id, only one record with delivery_id=4025931 is returned, and no duplicate composite primary key records appear.
SELECT * from erp_sdb_wms_delivery_items where item_id=7981775
[Problem Phenomenon and Impact]
Table structure:
CREATE TABLE `erp_sdb_wms_delivery_items` (
`item_id` bigint(20) NOT NULL,
`order_item_id` bigint(20) NULL DEFAULT NULL,
`delivery_id` bigint(20) NULL DEFAULT NULL,
`product_id` bigint(20) NULL DEFAULT NULL,
`shop_product_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`bn` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`product_name` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`number` bigint(20) NULL DEFAULT NULL,
`pick_number` bigint(20) NULL DEFAULT NULL,
`addon` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL,
`sell_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`iscustomitem` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`unique_code_status` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`unique_code_status_lasttime` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`unique_code_status_op_id` bigint(20) NULL DEFAULT NULL,
`is_freeze` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`freeze_time` bigint(20) NULL DEFAULT NULL,
`unique_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`picurl` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`photo` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL,
`photo_design` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL,
`photo_ai` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`photo_append` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL,
`word_photo` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`word_append` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL,
`letter_photo` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`letter_append` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL,
`verify` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`verify_num` bigint(20) NULL DEFAULT NULL,
`price` double NULL DEFAULT NULL,
`sale_price` double NULL DEFAULT NULL,
`pmt_price` double NULL DEFAULT NULL,
`custom_type` int(11) NULL DEFAULT NULL,
`ispickup` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`checknum` bigint(20) NULL DEFAULT NULL,
`photoimgispull` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`wordphotoimgispull` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`letterphotoimgispull` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`glasses_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`glasses_sendtime` bigint(20) NULL DEFAULT NULL,
`defective_goods` int(11) NULL DEFAULT NULL,
`defective_memo` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`defective_supplier` bigint(20) NULL DEFAULT NULL,
`defective_time` bigint(20) NULL DEFAULT NULL,
`clarity_photo` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`check_clarity` bigint(20) NULL DEFAULT NULL,
`clarity_time` bigint(20) NULL DEFAULT NULL,
`clarity_type` bigint(20) NULL DEFAULT NULL,
`is_urgent` int(11) NULL DEFAULT NULL,
`urgent_opid` bigint(20) NULL DEFAULT NULL,
`gspdf_status` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`gspdf_memo` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL,
`gspdf_time` bigint(20) NULL DEFAULT NULL,
`myjit_pull_status` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`myjit_pull_time` bigint(20) NULL DEFAULT NULL,
`gspdf_order_sn` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`gspdf_invoice_no` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`zworders_status` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`zworders_memo` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL,
`zworders_time` bigint(20) NULL DEFAULT NULL,
`zworders_sn` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`zworders_no` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`is_only_product` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`clarity_intimes` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
`erpsource` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
PRIMARY KEY (`item_id`, `erpsource`) USING BTREE,
INDEX `index_unique_code`(`unique_code`) USING BTREE,
INDEX `index_order_item_id`(`order_item_id`) USING BTREE,
INDEX `index_gspdf_status`(`gspdf_status`) USING BTREE,
INDEX `ind_ido`(`ispickup`, `delivery_id`, `order_item_id`) USING BTREE,
INDEX `ind_number_delivery`(`delivery_id`, `number`) USING BTREE,
INDEX `ind_zworders_status`(`zworders_status`) USING BTREE,
INDEX `ind_bn_status_code`(`bn`, `delivery_id`, `unique_code`) USING BTREE,
INDEX `ind_unique_code_status`(`unique_code_status`) USING BTREE,
INDEX `idx_deliveryid_customtype_isfreeze_itemid_productid`(`delivery_id`, `custom_type`, `is_freeze`, `item_id`, `product_id`) USING BTREE,
INDEX `idx_deliveryid_uniquecode_productid`(`delivery_id`, `unique_code`, `product_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Compact;
[Attachment]
Please provide the version information of each component, such as cdc/tikv, which can be obtained by executing cdc version/tikv-server --version.