为什么在缩小列和仅获取第一行时会产生不同的结果?

时间:2021-05-09 13:16:36

I'm running two queries in DB2

我在DB2中运行两个查询

SELECT * from mrptable FETCH FIRST ROW ONLY
--result for mrpcolumn = 1150131

SELECT mrpcolumn FROM mrptable FETCH FIRST ROW ONLY
--result for mrpcolumn = 0

Why would these two results be different?

为什么这两个结果会有所不同?

1 个解决方案

#1


8  

You have no order by clause on either query, so the result set ordering is indeterminate. You could even run the same query twice and get different results.

在任一查询中都没有order by子句,因此结果集排序是不确定的。您甚至可以运行两次相同的查询并获得不同的结果。

There are many reasons why the results sets would not be in the same order. The most likely is that you have an index on mrpcolumn. This index covers the second query, so the query could use the index to get one row.

结果集的顺序不同的原因有很多。最有可能的是你在mrpcolumn上有一个索引。此索引涵盖第二个查询,因此查询可以使用索引获取一行。

The first would go to the datapages.

第一个是数据页。

Another reason would be execution in a parallel environment, where is it indeterminate which thread/process returns the first value.

另一个原因是在并行环境中执行,其中不确定哪个线程/进程返回第一个值。

When using fetch first clauses, you should generally be using order by.

使用fetch first子句时,通常应该使用order by。

#1


8  

You have no order by clause on either query, so the result set ordering is indeterminate. You could even run the same query twice and get different results.

在任一查询中都没有order by子句,因此结果集排序是不确定的。您甚至可以运行两次相同的查询并获得不同的结果。

There are many reasons why the results sets would not be in the same order. The most likely is that you have an index on mrpcolumn. This index covers the second query, so the query could use the index to get one row.

结果集的顺序不同的原因有很多。最有可能的是你在mrpcolumn上有一个索引。此索引涵盖第二个查询,因此查询可以使用索引获取一行。

The first would go to the datapages.

第一个是数据页。

Another reason would be execution in a parallel environment, where is it indeterminate which thread/process returns the first value.

另一个原因是在并行环境中执行,其中不确定哪个线程/进程返回第一个值。

When using fetch first clauses, you should generally be using order by.

使用fetch first子句时,通常应该使用order by。