为提高效率,请提供以下信息,问题描述清晰能够更快得到解决:
【 TiDB 使用环境】
生产环境
【概述】 场景 + 问题概述
周六下午三点多,原来正常执行的sql,突然不走索引了,导致整体的集群负载飙升
【背景】 做过哪些操作
收集表统计信息
【现象】 业务和数据库现象
整体的查询针对这个表全部进行全表扫描,使用hint强制走索引可以走索引,不强制所有该走索引的全部不走,统计信息正常。
12:28:31 sqldataviewpro> select * from INFORMATION_SCHEMA.TABLES where table_name=‘rtdw_dwd_order_bak’ ;
±--------------±---------------±-------------------±-----------±-------±--------±-----------±-----------±---------------±------------±----------------±-------------±----------±---------------±--------------------±------------±-----------±–
--------------±---------±---------------±--------------±--------------±--------------------------±-------------+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | TABLE_TYPE | ENGINE | VERSION | ROW_FORMAT | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH | MAX_DATA_LENGTH | INDEX_LENGTH | DATA_FREE | AUTO_INCREMENT | CREATE_TIME | UPDATE_TIME | CHECK_TIME | TA
BLE_COLLATION | CHECKSUM | CREATE_OPTIONS | TABLE_COMMENT | TIDB_TABLE_ID | TIDB_ROW_ID_SHARDING_INFO | TIDB_PK_TYPE |
±--------------±---------------±-------------------±-----------±-------±--------±-----------±-----------±---------------±------------±----------------±-------------±----------±---------------±--------------------±------------±-----------±–
--------------±---------±---------------±--------------±--------------±--------------------------±-------------+
| def | sqldataviewpro | rtdw_dwd_order_bak | BASE TABLE | InnoDB | 10 | Compact | 11959764 | 468 | 5601425546 | 0 | 765424896 | 0 | NULL | 2022-08-27 16:05:11 | NULL | NULL | ut
f8mb4_bin | NULL | | 订单主表 | 9154 | NOT_SHARDED(PK_IS_HANDLE) | CLUSTERED |
±--------------±---------------±-------------------±-----------±-------±--------±-----------±-----------±---------------±------------±----------------±-------------±----------±---------------±--------------------±------------±-----------±–
--------------±---------±---------------±--------------±--------------±--------------------------±-------------+
1 row in set (0.05 sec)
12:28:36 sqldataviewpro> show create table rtdw_dwd_order_bak \G;
*************************** 1. row ***************************
Table: rtdw_dwd_order_bak
Create Table: CREATE TABLE rtdw_dwd_order_bak
(
id
bigint(20) unsigned NOT NULL COMMENT ‘主键’,
biz_type
int(11) DEFAULT ‘0’ COMMENT ‘业务类型’,
order_no
varchar(32) DEFAULT ‘’ COMMENT ‘订单号’,
order_type
int(11) DEFAULT ‘0’ COMMENT ‘订单类型’,
order_sub_type
int(11) DEFAULT ‘0’ COMMENT ‘订单子类型’,
seller_id
bigint(20) DEFAULT ‘0’ COMMENT ‘商家id’,
store_id
bigint(20) DEFAULT ‘0’ COMMENT ‘门店id’,
store_order_no
varchar(64) DEFAULT NULL COMMENT ‘店内单号’,
user_id
bigint(20) DEFAULT ‘0’ COMMENT ‘用户id’,
mobile
varchar(64) DEFAULT NULL COMMENT ‘联系方式’,
addr_id
int(11) DEFAULT ‘0’ COMMENT ‘收货地址ID’,
source
int(11) DEFAULT ‘0’ COMMENT ‘订单来源’,
source_no
varchar(256) DEFAULT ‘’ COMMENT ‘来源单号’,
from_system
int(11) DEFAULT ‘0’ COMMENT ‘上送方’,
source_info
varchar(1024) DEFAULT NULL COMMENT ‘来源信息’,
total_amount
int(11) DEFAULT ‘0’ COMMENT ‘订单总金额’,
cost_amount
int(11) DEFAULT ‘0’ COMMENT ‘成本金额’,
pack_amount
int(11) DEFAULT ‘0’ COMMENT ‘打包费’,
item_amount
int(11) DEFAULT ‘0’ COMMENT ‘商品总金额’,
freight_amount
int(11) DEFAULT ‘0’ COMMENT ‘运费总金额’,
discount_amount
int(11) DEFAULT ‘0’ COMMENT ‘优惠总金额’,
actual_amount
int(11) DEFAULT ‘0’ COMMENT ‘实付金额’,
pay_amount
int(11) DEFAULT ‘0’ COMMENT ‘支付金额’,
change_amount
int(11) DEFAULT ‘0’ COMMENT ‘找零金额’,
pay_type
int(11) DEFAULT ‘0’ COMMENT ‘支付方式’,
pay_model
int(11) DEFAULT ‘0’ COMMENT ‘结账模式’,
payer
bigint(20) DEFAULT ‘0’ COMMENT ‘付款人’,
pay_no
varchar(256) DEFAULT NULL COMMENT ‘支付单号’,
third_pay_no
varchar(256) DEFAULT NULL COMMENT ‘第三方支付单号’,
pay_info
varchar(1024) DEFAULT NULL COMMENT ‘支付信息’,
is_alone
int(11) DEFAULT ‘0’ COMMENT ‘是否独立收款’,
pay_status
int(11) DEFAULT ‘0’ COMMENT ‘支付状态’,
invoice_type
int(11) DEFAULT ‘0’ COMMENT ‘发票类型’,
performance_type
int(11) DEFAULT ‘0’ COMMENT ‘履约类型’,
is_immediate_performance
int(11) DEFAULT ‘0’ COMMENT ‘是否预约履约’,
performance_platform
varchar(128) DEFAULT NULL COMMENT ‘履约平台’,
performance_info
varchar(1024) DEFAULT NULL COMMENT ‘履约信息’,
activity_info
varchar(1024) DEFAULT NULL COMMENT ‘活动信息’,
item_info
text DEFAULT NULL COMMENT ‘商品信息’,
discount_info
text DEFAULT NULL COMMENT ‘折扣信息’,
seller_remarks
text DEFAULT NULL,
buyer_remarks_temp
text DEFAULT NULL COMMENT ‘用户备注’,
buyer_remarks
text DEFAULT NULL COMMENT ‘买家备注’,
is_receipt
int(11) DEFAULT ‘0’ COMMENT ‘是否打印’,
receipt_terminal
varchar(64) DEFAULT NULL COMMENT ‘打印机终端’,
status
int(11) DEFAULT ‘0’ COMMENT ‘状态’,
after_sale_status
int(11) DEFAULT ‘0’ COMMENT ‘退款状态’,
receive_status
int(11) DEFAULT ‘0’ COMMENT ‘接单状态’,
performance_status
int(11) DEFAULT ‘0’ COMMENT ‘履约状态’,
comment_status
int(11) DEFAULT ‘0’ COMMENT ‘评论状态’,
refusal_reasons
varchar(256) DEFAULT NULL COMMENT ‘拒单理由’,
order_at
datetime DEFAULT NULL COMMENT ‘下单时间’,
pay_at
datetime DEFAULT NULL COMMENT ‘支付时间’,
comment_at
datetime DEFAULT NULL COMMENT ‘评价时间’,
completed_at
datetime DEFAULT NULL COMMENT ‘订单完成时间’,
receive_at
datetime DEFAULT NULL COMMENT ‘接单时间’,
features
text DEFAULT NULL COMMENT ‘扩展信息’,
sync_flag
int(11) DEFAULT ‘0’ COMMENT ‘同步标识’,
created_at
datetime DEFAULT NULL COMMENT ‘创建时间’,
updated_at
datetime DEFAULT NULL COMMENT ‘修改时间’,
is_deleted
int(11) DEFAULT ‘0’ COMMENT ‘删除标识’,
version
int(11) DEFAULT ‘0’ COMMENT ‘版本号’,
amount
int(11) DEFAULT ‘0’,
wallet_amount
int(11) DEFAULT ‘0’,
use_wallet
int(11) DEFAULT ‘0’
PRIMARY KEY (id
) /*T![clustered_index] CLUSTERED */,
KEY idx_order_at
(order_at
),
KEY idx_order_no
(order_no
),
KEY idx_store_seller_at
(store_id
,order_at
),
KEY idx_store_pay
(store_id
,pay_at
),
KEY idx_seller_order
(seller_id
,order_at
),
KEY idx_updated_at
(updated_at
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT=‘订单主表’
1 row in set (0.01 sec)
12:30:02 sqldataviewpro> SHOW stats_healthy WHERE table_name=‘rtdw_dwd_order_bak’;
±---------------±-------------------±---------------±--------+
| Db_name | Table_name | Partition_name | Healthy |
±---------------±-------------------±---------------±--------+
| sqldataviewpro | rtdw_dwd_order_bak | | 93 |
±---------------±-------------------±---------------±--------+
12:30:06 sqldataviewpro> EXPLAIN SELECT
-> *
-> FROM
-> rtdw_dwd_order_bak
-> WHERE order_no=‘BT6001611909130084’;
±-------------------------±------------±----------±-------------------------±---------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
±-------------------------±------------±----------±-------------------------±---------------------------------------------------------------------+
| TableReader_7 | 0.99 | root | | data:Selection_6 |
| └─Selection_6 | 0.99 | cop[tikv] | | eq(sqldataviewpro.rtdw_dwd_order_bak.order_no, “BT6001611909130084”) |
| └─TableRangeScan_5 | 11959764.00 | cop[tikv] | table:rtdw_dwd_order_bak | range:[0,+inf], keep order:false |
±-------------------------±------------±----------±-------------------------±---------------------------------------------------------------------+
12:30:53 sqldataviewpro> EXPLAIN SELECT
-> *
-> FROM
-> rtdw_dwd_order_bak FORCE INDEX(idx_order_no)
-> WHERE order_no=‘BT6001611909130084’;
±------------------------------±--------±----------±-------------------------------------------------------±--------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
±------------------------------±--------±----------±-------------------------------------------------------±--------------------------------------------------------------------+
| IndexLookUp_7 | 0.99 | root | | |
| ├─IndexRangeScan_5(Build) | 0.99 | cop[tikv] | table:rtdw_dwd_order_bak, index:idx_order_no(order_no) | range:[“BT6001611909130084”,“BT6001611909130084”], keep order:false |
| └─TableRowIDScan_6(Probe) | 0.99 | cop[tikv] | table:rtdw_dwd_order_bak | keep order:false |
±------------------------------±--------±----------±-------------------------------------------------------±--------------------------------------------------------------------+
【问题】 当前遇到的问题
【业务影响】
业务超时
【TiDB 版本】
5.2.3
【应用软件及版本】
【附件】 相关日志及配置信息
- TiUP Cluster Display 信息
- TiUP CLuster Edit config 信息
监控(https://metricstool.pingcap.com/)
- TiDB-Overview Grafana监控
- TiDB Grafana 监控
- TiKV Grafana 监控
- PD Grafana 监控
- 对应模块日志(包含问题前后 1 小时日志)
若提问为性能优化、故障排查类问题,请下载脚本运行。终端输出的打印结果,请务必全选并复制粘贴上传。