‎2010 Nov 15 10:23 AM
Dear All,
In my code; I am having a SELECT DISTINCT. Since it is found that, the query is tabking much more time to execute, can anybody suggest a way to replace the code.
-
The code looks like..
SELECT DISTINCT column1 column2
INTO itab
BYPASSING BUFFER....
Can I use a code like this..
SELECT column1 column2
INTO...
followed by SORT itab by column1 column2. and DELETE ADJACENT DUPLICATES COMPARING column1 column2.
I want to know whether both will provide same output.
Regards
Ullas
‎2010 Nov 19 12:33 PM
To answer one of the initial questions: The output should be the same with SELECT DISTINCT and SORT/DELETE. And I can confirm that on some systems the SORT/DELETE might be faster than SELECT DISTINCT. Maybe it's even faster if you select directly into a sorted table, like:
DATA: itab TYPE SORTED TABLE OF dtab WITH NON-UNIQUE KEY colum1 colum2.
SELECT column1 column2
FROM dtab
INTO TABLE itab.
DELETE ADJACENT DUPLICATES FROM itab.
‎2010 Nov 15 10:37 AM
I think it would be good or easier to tell only if let us know what fields you are selecting, from which table your selcting and what is your where condition that you are passing to select them.
But still try using group by col1, col2 etc at the end of your SELECT statement to enhance the performance at best. Remember col1 etc specified with GROUP BY clause should be a part of the primary key or atleast a part of the Secondary key (INDEX's) of the table you are fetching from.
Bye.
‎2010 Nov 15 10:42 AM
Hello,
Why have you used BYPASSING BUFFER? I can suggest compare the 2 approaches in ABAP Runtime Tool(SE30) "Tips & Tricks" section & check which one is faster.
BR,
SUhas
‎2010 Nov 15 11:01 AM
BY PASSING BUFFER is must on DISTINCT.
Also rather than performance, I am afraid about the output. So 1st of all I need to know whether the mentioned logic provides same output or not.
-Ullas
Edited by: UllasU on Nov 15, 2010 12:10 PM
‎2010 Nov 15 12:28 PM
Hi,
There is no need to write the by pass buffer, when you used the distinct it automatically bypass the buffer.
when you used the distinct in select sql then system sort table whole table, search and provide the result.
Put the Order by in SQL and try.
‎2010 Nov 15 12:29 PM
BY PASSING BUFFER is must on DISTINCT
When using SELECT DISTINCT, SELECT overrides the buffer implicitly!
‎2010 Nov 16 4:35 PM
the SELECT DISTINCT can not use the table buffer ....
But, is your table in the table buffer?
If so, then you should use your second option, because this can use the table buffer and is at least 10 times faster.
... If the WHERE-clause also fits to the buffer setting.
If not, if the table in only in the database, then you should leave the DISTINCT where it is and chekc the WHERE-clause, whether it can use an index.
Siegfried
‎2010 Nov 19 12:33 PM
To answer one of the initial questions: The output should be the same with SELECT DISTINCT and SORT/DELETE. And I can confirm that on some systems the SORT/DELETE might be faster than SELECT DISTINCT. Maybe it's even faster if you select directly into a sorted table, like:
DATA: itab TYPE SORTED TABLE OF dtab WITH NON-UNIQUE KEY colum1 colum2.
SELECT column1 column2
FROM dtab
INTO TABLE itab.
DELETE ADJACENT DUPLICATES FROM itab.