The difference between "TOP" and "SAMPLE" in TeraData SQL

What is the difference between "TOP" and "SAMPLE" in TeraData SQL? They are the same?

+7
source share
1 answer

From TOP vs SAMPLE :

TOP 10 means "the first 10 lines in the sort order." If you do not have ORDER BY, then by extension it will be interpreted as a request of "ANY 10 lines" in any order. The optimizer, choosing the cheapest plan for free, can find and stop processing as soon as it has found enough lines to return.

If this request is the only thing on your system, you may see TOP always give you the same answer, but this behavior is NOT guaranteed.

SAMPLE, as you have noticed, does additional processing for randomization; the result set still maintains the same approximate distribution. At a very simple level, for example, he could select a random starting point for scanning the table and a row row to skip between the rows that returned.

+12
source

All Articles