mybatis limit data duplication and omission

One day, I wrote a CRUD and submitted the test to QA. Later, I remembered that I forgot to sort according to the rules, and then revised the code submission. At this time, QA threw me a dog, no, it was a bug.

My heart is full of sadness, and CRUD also has bugs. It seems that I can't get along and it's time to change lines. What should I do? Hurry up and take a look.

BUG description: There are duplications and omissions in the data queried by paging. Use a test table to describe this place.

CREATE TABLE `product_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  `partner_id` int ( 11 ) unsigned NOT  NULL  DEFAULT  ' 0 ' COMMENT ' Supplier ID ' ,
  `poi_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '门店ID',
  `product_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '商品ID',
  `quantity` decimal(18,6) NOT NULL DEFAULT '0.000000' COMMENT '数量',
  `created_time` datetime  NOT  NULL  DEFAULT  ' 1000-01-01 00:00:00 ' COMMENT ' created time ' ,
  `modify_time` datetime NOT NULL DEFAULT '1000-01-01 00:00:00' COMMENT '修改时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_partner_poi_product` (`partner_id`,`poi_id`,`product_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='商品表'

There are 8 pieces of data in the data table product_info.

Paging query the first page:

 

Paging query the second page:

 

 

Conclusion: From the figure, we can see that the data of id in (10, 40) appears twice, and the data of id in (7, 8) has not been detected. Data does appear to have duplications and omissions. My previous understanding of mybatis is that it will be sorted by ID by default, and I have doubts.

The first page seems to be sorted out of order, but it is not. This order is the order in which I write the data. The second page appears to be sorted by id.

That is to say, the two queries feel different sorting methods? Actually not. In fact, it uses heap sort.

So isn't it sorted by ID by default? In fact, in the case of non-limit, the default is really sorted by ID. If you don't believe me, look!

 

So how to solve the omission and duplication of paging query in the face of this situation? -- add sort field

 

But you see, after adding the sorting field, a piece of id in (3) data is still missing. what about this?

Let's first look at what is wrong with these data. You can see that the values ​​corresponding to this sort field are all the same. I suspect that when it is sorted, the arrangement of the same values ​​is also heap sorting. There is no verification. Who knows, please correct me.

Therefore, when the second page is limited, the records are sorted differently these days, but starting from the 6th item, 3 is missed and 10 is repeated.

 

So what exactly is going on here? -- or that sentence to increase the sorting field!

Add an ID field for sorting, so that you can close the bug, otherwise you will really have to change your line.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324774169&siteId=291194637