cancel
Showing results for 
Search instead for 
Did you mean: 

aggregate function queries and order by queries

Former Member
0 Kudos
select max(p_retailprice), min(p_retailprice) from part

This query takes very long tiime to execute. PART table is of the TPCH benchmark with cardinality 200000.

moreover even the query

select p_retailprice from dbo.part ORDER BY p_retailprice ASC

is taking very long time to execute.

The execution time is of the order of 30-60 mins.

EnableMinMaxOptimization is set to YES.

Kindly suggest if any parameter can increase the efficiency of the query.

Accepted Solutions (1)

Accepted Solutions (1)

markus_doehr2
Active Contributor
0 Kudos

Try setting

READAHEAD_TABLE_THRESHOLD to e. g. 500

and retry the query.

Markus

Answers (1)

Answers (1)

lbreddemann
Active Contributor
0 Kudos

Hi there,

while the approach to enable prefetching (READAHEAD_TABLE_THRESHOLD >0) may solve this issue for MaxDBs with version >7.6.05 (but not for 7.7 !) the much more effective solution would be to create an appropriate index.

Just create an index on p_retailprice and both the min/max optimization will work as well as the order by will be much quicker.

See, the min/max optimization makes use of the B*TREE structure to find the left/right most outer value.

The same goes for the order by. Without an Index a temporary file needs to be created, all data read and sorted and finally the temp. file is read for the output.

best regards,

Lars