gpt4 book ai didi

mysql - 优化大 `IN` SQL

转载 作者:行者123 更新时间:2023-11-28 23:47:19 25 4
gpt4 key购买 nike

我有一个这么大的 SQL:

SELECT id,kdt_id,kdt_goods_id,fx_price,min_retail_price,max_retail_price,
fx_count,stock_num,sold_num,recommend_level,is_display,is_delete,
quit_time,review_status,fx_auth,level_discount_auth,is_fx_delete,
sold_status
FROM apple_goods
WHERE 1 and `kdt_goods_id` in (
'44089839','44089839','44089839','44089839','44089839',
'44089839','44089839','44089839','44089839','44089839',
'44089839','44089839','44089839','44089839','44089839',
'44089839','44089839','44089839','44089839','44089839',
'44089839','44089839','44089839','44089839','44089839',
'96611525','96611525','96611525','96611525','96611525',
'96611525','96611525','96611525','96611525','96611525',
'96611525','96611525','96611525','96611525','96611525',
'96611525','96611525','96611525','96611525','96611525',
'96611525','96611525','96611525','96611525','96611525',
'96611525','96611525','96611525','96611525','142061451',
'142061451','142061451','142061451','142061451','142061451',
'142061451','142061451','142061451','142061451','142061451',
'142061451','142061451','142061451','142061451','142061451',
'142061451','142061451','142061451','142801551','142801551',
'142801551','142801551','142801551','142801551','142801551',
'142801551','142801551','142801551','142801551','142801551',
'142801551','142801551','142801551','142801551','142801551',
'142801551','142801551','142801551','142801551','142801551',
'143381529','143381529','143381529','143381529','143381529',
'143381529','147713054','147713054','147713054','147713054',
'147713054','147713054','147713054','148164398','148164398',
'148164398','148164398','148164398','148164398','148164398',
'148164398','148164398','148164398','148164398','148296160',
'148296160','148296160','148296160','148296160','148296160',
'151063722','151063722','151063722','151063722','151063722',
'151063722','151063722','151063722','151063722','151063722',
'151063722','151063722','151063722','151063722','151063722',
'151063722','151063722','151063722','151063722','151063722',
'151063722','153933372','153933372','153933372','153933372',
'153933372','153933372','154447237','154447237','154447237',
'154447237','154447237','154447237','154447237','158137781',
'158137781','158137781','158137781','158137781','158137781',
'158217358','158217358','158217358','158217358','158217358',
'158217358','158217358','158217358','158217358','158217358',
'158217358','158217358','158217358','158246547','158246547',
'158246547','158246547','158246547','158246547','158246547',
'158246547','158246547','158246547','158246547','158246547',
'158246547','158246547','158246547','158246547','158246547',
'158246547','158246547','158246547','158246547','160734561',
'160734561','160734561','160734561','160734561','160734561',
'162435844','162435844','162435844','162435844','162435844',
'162435844','162435844','162435844','162435844','162435844',
'162435844','162435844','162435844','163784258','163784258',
'163784258','163784258','163784258','163784258','163784258',
'163784258','163784258','163784258','163784258','163784258',
'163784258','163784258','163784258','163784258','163784258',
'163784258','163784258','163800813','163800813','163800813',
'163800813','163800813','163800813','163800813','163800813',
'163800813','163800813','163800813','163803246','163803246',
'163803246','163803246','163803246','163803246','164617535',
'164617535','164617535','164617535','164617535','164617535',
'164617535','164617535','164617535','164617535','164617535',
'164617535','164617535','164617535','164617535','164617535',
'164617535','164617535','164617535','164617535','164617535')

如何优化?

解释:

```
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: apple_goods
type: range
possible_keys: kdt_goods_id
key: kdt_goods_id
key_len: 4
ref: NULL
rows: 20
Extra: Using index condition
1 row in set (0.00 sec)

```

最佳答案

我已经从您的 IN 中删除了重复项,可能会针对创建临时表进行基准测试。

SELECT id,kdt_id,kdt_goods_id,fx_price,min_retail_price,max_retail_price,
fx_count,stock_num,sold_num,recommend_level,is_display,is_delete,
quit_time,review_status,fx_auth,level_discount_auth,is_fx_delete,
sold_status
FROM apple_goods
WHERE 1 and `kdt_goods_id` in
('96611525',
'44089839',
'164617535',
'163803246',
'163800813',
'163784258',
'162435844',
'160734561',
'158246547',
'158217358',
'158137781',
'154447237',
'153933372',
'151063722',
'148296160',
'148164398',
'147713054',
'143381529',
'142801551',
'142061451')

关于mysql - 优化大 `IN` SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33385824/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com