Query Tool MAX() , Order By ... statements speed question with SQL Server

Good morning
I have a question, something is unclear how query SQL behaves:

select max(id) 
from t1@sql

with 588K records in the table, Query Tool takes 22 seconds to print the result:

Execute query with max

The query:

select id 
from   t1@sql 
by     id desc 
limit  1 

with 588K records in the table, Query Tool takes 23 seconds to print the result.

It seems that both statement are not passing the MAX nor the ORDER BY to the SQL Server data container on @sql, instead loading all the records and doing the operation Query Tool side, not SQL server side.

Am I wrong?

You are correct.

Invantive SQL currently does neither forward group functions like max nor order by to the data container. This also holds for the next release of the Invantive SQL engine, which focuses on optimization technologies.

In theory it is possible to forward group functions and the sorting to the data container, but given insufficient market demand we have not created it (yet).

A workaround is to use native SQL such as:

  execute native '...'

or with a loop like:

  for r in
  ( execute native '...'
  end loop;

Disadvantage is that this approach requires knowledge of the syntax of the data container’s native platform. Advantage is that it allows access to almost all native optimization techniques available, including platform-specific hints.


For example, the following Invantive SQL query on a large table take 2.7 seconds:

select max(id) 
from   lic@sql

The alterantive using native SQL takes 180 ms:

  l_max_id pls_integer;
  execute native 'select max(id) from lic' 
  into l_max_id 
  datacontainer 'sql'
1 Like