高效的DB2查询分页和显示总页数?

时间:2021-12-11 18:01:51

This post shows some hacks to page data from DB2:

这篇文章展示了一些来自DB2的页面数据:

How to query range of data in DB2 with highest performance?

如何以最高性能查询DB2中的数据范围?

However it does not provide a way to show the total number of rows (like MySQL's CALC_FOUND_ROWS).

但是它没有提供显示总行数的方法(如MySQL的CALC_FOUND_ROWS)。

SELECT SQL_CALC_FOUND_ROWS thread_id AS id, name, email
FROM threads WHERE email IS NOT NULL
LIMIT 20 OFFSET 200

And in MySQL I can follow that up with

在MySQL中我可以跟着它

SELECT FOUND_ROWS()

to get the total number of rows. The first part is fairly easy to duplicate with recent versions of DB2. I can't find any results on Google for a reasonable equivalent to the second query (I don't want temp tables, subqueries, or other absurdly inefficient solutions).

获取总行数。第一部分很容易与最新版本的DB2重复。我在Google上找不到任何与第二个查询相当的结果(我不想要临时表,子查询或其他荒谬的低效解决方案)。

1 个解决方案

#1


1  

I don't think this exists in DB2.

我认为这不存在于DB2中。

Note that the total number of rows is a value that needs extra calculation to obtain. It isn't just lying around somewhere--it would have to be specifically built into the LIMIT logic. Which it doesn't look like they did.

请注意,总行数是需要额外计算才能获得的值。它不仅仅是在某个地方 - 它必须专门构建在LIMIT逻辑中。它看起来不像他们。

#1


1  

I don't think this exists in DB2.

我认为这不存在于DB2中。

Note that the total number of rows is a value that needs extra calculation to obtain. It isn't just lying around somewhere--it would have to be specifically built into the LIMIT logic. Which it doesn't look like they did.

请注意,总行数是需要额外计算才能获得的值。它不仅仅是在某个地方 - 它必须专门构建在LIMIT逻辑中。它看起来不像他们。