不带limitSQL语句执行结果不准确

TiDB3.0.0 GA

建表语句如下:

CREATE TABLE `topic` (
  `platformid` varchar(255) DEFAULT NULL,
  `appid` varchar(255) DEFAULT NULL,
  `topicid` varchar(255) DEFAULT NULL,
  `content_type` int(11) DEFAULT NULL,
  `video_type` int(11) DEFAULT NULL,
  `title` varchar(2000) DEFAULT NULL,
  `url` varchar(2000) DEFAULT NULL,
  `author` varchar(255) DEFAULT NULL,
  `create_time` timestamp NULL DEFAULT NULL,
  `pub_time` timestamp NULL DEFAULT NULL,
  `summary` varchar(5000) DEFAULT NULL,
  `content` varchar(5000) DEFAULT NULL,
  `category` varchar(5000) DEFAULT NULL,
  `tags` varchar(5000) DEFAULT NULL,
  `keywords` varchar(5000) DEFAULT NULL,
  `topic_contentids` varchar(2000) DEFAULT NULL,
  `style_card_source_channelid` varchar(255) DEFAULT NULL,
  `style_card_type` int(11) DEFAULT NULL,
  `source_type` int(11) DEFAULT NULL,
  `source_id` varchar(255) DEFAULT NULL,
  `fingerprint` bigint(20) DEFAULT NULL,
  `m_create_time` timestamp NULL DEFAULT NULL,
  `m_update_time` timestamp NULL DEFAULT NULL,
  UNIQUE KEY `u_pat` (`platformid`,`appid`,`topicid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

执行SQL语句如下:


set @rowidex := 1;
set @last_fingerprint := -1;
select
 platformid ,
 appid ,
 topicid ,
 content_type ,
 title ,
 url ,
 author ,
 create_time ,
 pub_time ,
 summary ,
 category ,
 tags ,
 keywords ,
 topic_contentids ,
 style_card_source_channelid ,
 style_card_type ,
 source_type ,
 source_id ,
 fingerprint ,
 if(@last_fingerprint = fingerprint , @rowidex := @rowidex + 1 , @rowidex := 1) row_num ,
 @last_fingerprint := fingerprint last_fingerprint ,
 now() m_create_time ,
 now() m_update_time
from topic
order by fingerprint
;

这条sql加上limit语句row_num返回正常,去掉limit的话不准确了

下图没有limit的sql执行结果:



下图是带limit的sql执行结果

  1. limit 的话是 limit 多少?
  2. 看看 select @@tidb_max_chunk_size; 的值是多少呢?

limit 20000;

  1. 带了 limit 的完整 SQL 能发一下么;
  2. 能 explain 这个 SQL 发一下执行计划吗;
  3. 最好用 v3.0+ 版本的 window function 试一下, row_num 是通过变量模拟生成的, 结果可能会根据执行顺序的不同而改变, TiDB 目前执行器实现不能保证这种模拟方式的结果是稳定的;
set @rowidex := 1;
set @last_fingerprint := -1;
select
platformid ,
appid ,
topicid ,
content_type ,
title ,
url ,
author ,
create_time ,
pub_time ,
summary ,
category ,
tags ,
keywords ,
topic_contentids ,
style_card_source_channelid ,
style_card_type ,
source_type ,
source_id ,
fingerprint ,
if(@last_fingerprint = fingerprint , @rowidex := @rowidex + 1 , @rowidex := 1) row_num ,
@last_fingerprint := fingerprint last_fingerprint ,
now() m_create_time ,
now() m_update_time
from topic
order by fingerprint
limit 20000
;

执行计划:


@deepeye 能用 window func 试一下吗, 这种用变量模拟的行为 TiDB 不能保证稳定的.

@deepeye 看起来你们执行计划没有截图全, 没有看到 rownum 相关的, 能截图全一些吗;