“TOP”与“TOP”之间的区别和“样本”在 TeraData SQL 中

发布于 2024-11-15 22:00:44 字数 50 浏览 4 评论 0原文

TeraData SQL 中的“TOP”和“SAMPLE”有什么区别?它们是一样的吗?

What is the difference between "TOP" and "SAMPLE" in TeraData SQL? Are they the same?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩心态 2024-11-22 22:00:44

来自TOP 与 SAMPLE

TOP 10 表示“已排序的前 10 行”
order”。如果您没有 ORDER BY,
那么通过扩展它将是
解释为要求“ANY 10
rows”以任意顺序。优化器是
自由选择最便宜的计划吧
可以尽快找到并停止处理
因为它已找到足够的行来返回。

如果这个查询是唯一的
在您的系统上运行时,可能会出现 TOP
总是给你一模一样的
答案,但这种行为不是
保证。

正如您所观察到的,SAMPLE 确实
尝试随机化的额外处理
结果集仍保持相同
近似分布。在一个非常
简单的水平,例如,它可以
选择一个随机点开始
扫描桌子和一些
在行之间跳过的行
返回。

From TOP vs SAMPLE:

TOP 10 means "first 10 rows in sorted
order". If you don't have an ORDER BY,
then by extension it will be
interpreted as asking for "ANY 10
rows" in any order. The optimizer is
free to select the cheapest plan it
can find and stop processing as soon
as it has found enough rows to return.

If this query is the only thing
running on your system, TOP may appear
to always give you exactly the same
answer, but that behavior is NOT
guaranteed.

SAMPLE, as you have observed, does
extra processing to try to randomize
the result set yet maintain the same
approximate distribution. At a very
simple level, for example, it could
pick a random point at which to start
scanning the table and a number of
rows to skip between rows that are
returned.

北恋 2024-11-22 22:00:44

“Sample”命令:

Sel * from tablename
sample 100

这将为您提供表中 100 条不同记录的样本。
每次运行 SAMPLE 命令时都会给出不同的结果。

TOP 命令:

sel top 100 * from tablename;

这将给出表的前 100 行。
每次运行 TOP 命令时都会给出相同的结果。

‘Sample’ command:

Sel * from tablename
sample 100

That will give you a sample of 100 different records from the table.
The SAMPLE command will give DIFFERENT results each time you run it.

TOP command:

sel top 100 * from tablename;

This will give the first 100 rows of the table.
The TOP command will give you THE SAME results each time you run it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文