非常慢的查询,请帮忙看看
表: CREATE TABLE accountdb.PreReg ( Id bigint NOT NULL, Account varchar(50) NOT NULL, Password varchar(50) NOT NULL, Salt varchar(32) NOT NULL, IsUsed tinyint NOT NULL DEFAULT '0', UsedTime datetime NOT NULL DEFAULT '1970-01-01 00:00:00', Prefix varchar(50) NULL, RndNum int NULL, RowVersion bigint NULL, PRIMARY KEY (Id) ) ENGINE=InnoDB AUTO_INCREMENT=100 COLLATE=utf8_general_ci ; CREATE INDEX IX_Account ON accountdb.PreReg (Account); CREATE INDEX IX_PreReg_Prefix_RndNum ON accountdb.PreReg (Prefix,RndNum)
版本:5.7.1-TiDB-v1.0.8-1-gaacba4a 语句: select * from PreReg where IsUsed=0 and Prefix='m' and RndNum>floor(RAND()*9999999) order by RndNum limit 1 数据总量:19000 tidb 0.13秒 ,mysql:0秒.... 这1.9万数据啊.......
服务器配置:3个128G SSD的KV i5的cpu
ps,请问有其他的联系方式吗?q群,微信群,或者别的都可以.
explain 的情况
| IndexScan_29 | cop | table:PreReg, index:Prefix, RndNum, range:[m |
1.25 | ||
|---|---|---|---|---|---|
| TableScan_30 | Selection_31 | cop | table:PreReg, keep order:false | 1.25 | |
| Selection_31 | TableScan_30 | cop | eq(accountdb.prereg.isused, 0) | 1 | |
| IndexLookUp_32 | Selection_2 | root | index:IndexScan_29, table:Selection_31 | 1 | |
| Selection_2 | Limit_7 | IndexLookUp_32 | root | gt(cast(accountdb.prereg.rndnum), floor(mul(rand(), 9999999))) | 1 |
| Limit_7 | Selection_2 | root | offset:0, count:1 | 1 |
MYSQL的Explain
| 1 | SIMPLE | PreReg | (NULL) | ref | IX_Prefix_RndNum | IX_Prefix_RndNum | 153 | const | 9559 | 3.33 | Using index condition; Using where |
|---|
@mine1202 TiDB 什么版本?需要结合实际环境 trace SQL 执行过程,请发邮件到 [email protected],我们通过更便捷的方式交流
在 WHERE/HAVING/ON 条件中,我们会分析主键或索引键的查询返回。如数字、日期类型的比较符,如大于、小于、等于以及大于等于、小于等于,字符类型的 LIKE 符号等。 值得注意的是,我们只支持比较符一端是列,另一端是常量,或可以计算成某一常量的情况,类似 year(birth_day) < 1992 的查询条件是不能利用索引的
虽然以上讲的是索引,但是是否在使用where条件中,尽量不使用变量? RndNum>floor(RAND()*9999999) 瞎猜哈哈,试试看?
@mine1202 Any update?
Hi all, because this issue is too old, I'll close it for now. Feel free to open another issue in TiDB repo or this repo if you still have questions~