oracle 如何限制 Ingres 中任意查询的结果集大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to limit result set size for arbitrary query in Ingres?
提问by Craig Day
In Oracle, the number of rows returned in an arbitrary query can be limited by filtering on the "virtual" rownum
column. Consider the following example, which will return, at most, 10 rows.
在 Oracle 中,可以通过过滤“虚拟”rownum
列来限制任意查询中返回的行数。考虑以下示例,它最多返回 10 行。
SELECT * FROM all_tables WHERE rownum <= 10
Is there a simple, generic way to do something similar in Ingres?
在 Ingres 中是否有一种简单、通用的方法来做类似的事情?
回答by Tnilsson
回答by Craig Day
select * from myTable limit 10 does not work.
select * from myTable limit 10 不起作用。
Have discovered one possible solution:
发现了一种可能的解决方案:
TIDs are "tuple identifiers" or row addresses. The TID contains the page number and the index of the offset to the row relative to the page boundary. TIDs are presently implemented as 4-byte integers. The TID uniquely identifies each row in a table. Every row has a TID. The high-order 23 bits of the TID are the page number of the page in which the row occurs. The TID can be addressed in SQL by the name `tid.'
So you can limit the number of rows coming back using something like:
因此,您可以使用以下内容限制返回的行数:
select * from SomeTable where tid < 2048
The method is somewhat inexact in the number of rows it returns. It's fine for my requirement though because I just want to limit rows coming back from a very large result set to speed up testing.
该方法在返回的行数方面有些不准确。不过,这对我的要求很好,因为我只想限制从非常大的结果集中返回的行以加快测试速度。
回答by Tnilsson
Hey Craig. I'm sorry, I made a Ninja Edit. No, Limit 10 does not work, I was mistaken in thinking it was standard SQL supported by everyone. Ingres uses (according to doc) "First" to solve the issue.
嗨,克雷格。对不起,我做了一个忍者编辑。不,限制 10 不起作用,我误以为它是每个人都支持的标准 SQL。Ingres 使用(根据 doc)“First”来解决这个问题。
回答by Craig Day
Hey Ninja editor from Stockholm! No worries, have confirmed that "first X" works well and a much nicer solution than I came up with. Thankyou!
嘿,来自斯德哥尔摩的忍者编辑!不用担心,已经确认“第一个 X”运行良好,并且是比我想出的更好的解决方案。谢谢!