Oracle SELECT * FROM LARGE_TABLE - takes minutes to respond

Inquisitor Shm

So I have a simple table with 5 or so columns, one of which is a clob containing some JSON data.

I am running

  1. SELECT * FROM BIG_TABLE
  2. SELECT * FROM BIG_TABLE WHERE ROWNUM < 2
  3. SELECT * FROM BIG_TABLE WHERE ROWNUM = 1
  4. SELECT * FROM BIG_TABLE WHERE ID=x

I expect that any fractionally intelligent relational database would return the data immediately. We are not imposing order by/group by clauses, so why not return the data as and when you find it?

Of all the forms of SELECT statements above, only 4. returned in a sub-second manner. This is unexpected for 1-3 which are returning between 1 and 10 minutes before the query shows any responses in SQL Developer. SQL Developer has the standard SQL Array Fetch Size of 50 (JDBC Fetch size of 50 rows) so at a minimum, it is taking 1-10 minutes to return 50 rows from a simple table with no joins on a super high-performance RAC cluster backed by fancy 4-tiered EMC disk subsystem.

Explain plans show a table scan. Fine, but why should I wait 1-10 minutes for the results with rownum in the WHERE clause?

What is going on here?

Inquisitor Shm

OK - I found the issue. ROWNUM does not operate like I thought it did and in the code above it never stops the full table scan.

This is because:

RowNum is assigned during the predicate operation (where clause evaluation) and incremented afterwards, i.e.: your row makes it into the result set and then gets rownum assigned.

In order to filter by rownum you need to already have it exist, something like ...

SELECT * FROM (SELECT * FROM BIG_TABLE) WHERE ROWNUM < 1

In effect what this means is that there is no way to filter out the top 5 rows from a table without having first selected the entire table if no other filter criteria are involved.

I solved my problem like this...

    SELECT * FROM (SELECT * FROM BIG_TABLE WHERE 
  DATE_COL BETWEEN :Date1 AND :Date2) WHERE ROWNUM < :x;

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Ubuntu takes 7 minutes to boot

분류에서Dev

select * from (select * from table)

분류에서Dev

Oracle select query for link table

분류에서Dev

How to delete large amount of data from Oracle table in batches

분류에서Dev

Kubuntu takes more than 2 minutes to boot!

분류에서Dev

Oracle SQL: Select rows from table A with fallback to joined table A and B. (union, group by,...)

분류에서Dev

SELECT FROM table, ORDER BY IF (...)

분류에서Dev

Select from another select without temporary table?

분류에서Dev

SELECT array of cols FROM table

분류에서Dev

RegEx in select from table in db

분류에서Dev

SELECT * FROM table Where CURDATE ()

분류에서Dev

cygwin on win7 x64 takes long time to respond

분류에서Dev

Oracle : INSERT on condition from other table

분류에서Dev

CREATE TABLE AS select * from partitioned table

분류에서Dev

SELECT * INTO [newdatabase]. [table] FROM [otherdatabase]. [table]

분류에서Dev

Oracle Select Query optimization

분류에서Dev

Oracle select * 및 rownum

분류에서Dev

select * from table where id = select max id in codeigniter

분류에서Dev

how select from table where datetime=date

분류에서Dev

Select fields from table with DISTINCT field

분류에서Dev

LINQ select data from many table

분류에서Dev

MySQL Best select query from two table

분류에서Dev

Select from table where the date is later then today

분류에서Dev

Select drop down from table array

분류에서Dev

How to select the following things from psql table?

분류에서Dev

SELECT * FROM MULTIPLE + DYNAMIC table_name

분류에서Dev

mysql select * from table group by id with rollup

분류에서Dev

Oracle SQL query taking too long like 60 minutes to execute

분류에서Dev

SQLSyntaxErrorException when i select a sequence from DB (ORACLE 11g)

Related 관련 기사

뜨겁다태그

보관