“TOP"和“TOP"的区别和“样品"在 TeraData SQL 中 [英] Difference between "TOP" and "SAMPLE" in TeraData SQL

查看:34
本文介绍了“TOP"和“TOP"的区别和“样品"在 TeraData SQL 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

来自 TOP vs SAMPLE:

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

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.

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

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,正如您所观察到的,确实尝试随机化的额外处理结果集仍然保持不变近似分布.在一个很简单的水平,例如,它可以选择一个随机点开始扫描表格和一些在行之间跳过的行返回.

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.

这篇关于“TOP"和“TOP"的区别和“样品"在 TeraData SQL 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆