IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

which predicate results in a order on INDEX.


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ruodeer

New User


Joined: 06 Jul 2007
Posts: 58
Location: home

PostPosted: Fri May 16, 2008 8:55 am
Reply with quote

Hello everyone,

her is the Index defination:
Code:
( C1 ASC, C2 DESC,C3 ASC)


I am confused about the following two predicate
which will result in a order:

Code:
where c1='A'  order by C2 ASC,C3 DESC
where c1='A'  order by C1 ASC,C2 ASC


thanks!
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri May 16, 2008 11:49 am
Reply with quote

Hello,

Quote:
which will result in a order:
Please clarify your question.

Both will return rows in the specified order.

I also do not understand why this "( C1 ASC, C2 DESC,C3 ASC) " was posted.
Back to top
View user's profile Send private message
mytags

New User


Joined: 28 Apr 2008
Posts: 63
Location: US

PostPosted: Fri May 16, 2008 12:06 pm
Reply with quote

hi,
It will get displayed by ascending order of c2 and descending order of C3 i think your confusion is got over now.
Thanks
Hari. icon_biggrin.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri May 16, 2008 12:29 pm
Reply with quote

Hello,

Quote:
It will get displayed by ascending order of c2 and descending order of C3
Not necessarily - that depends on which code is used - 2 separate situations are posted. . .

Quote:
i think your confusion is got over now.
I believe you've only added confusion.
Back to top
View user's profile Send private message
ruodeer

New User


Joined: 06 Jul 2007
Posts: 58
Location: home

PostPosted: Fri May 16, 2008 12:43 pm
Reply with quote

Dick & mytags,thanks for your kindly reply.
sorry for confusion.
let me try to clarify:

saying I want to query three columns on a table , to avoid sorts, the DBA has defined an index by specifying
Code:
( C1 ASC, C2 DESC,C3 ASC)
.

which of the following will result in a sort?

Code:
where c1='A'  order by C2 ASC,C3 DESC
where c1='A'  order by C1 ASC,C2 ASC


hopefully I am clear ,thanks!
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri May 16, 2008 12:46 pm
Reply with quote

Hello,

Quote:
which of the following will result in a sort?
Both of them - neither can be met by the index directly.
Back to top
View user's profile Send private message
ruodeer

New User


Joined: 06 Jul 2007
Posts: 58
Location: home

PostPosted: Fri May 16, 2008 1:24 pm
Reply with quote

thanks Dick,actually I got this question on a DB2 certification test sample , and the answer is
Code:
  where c1='A'  order by C2 ASC,C3 DESC
may not result a sort, and I donot understand the answer so I put the question here, thank you anyway.

So as per my unserstanding only the
Code:
ORDER BY C1 ASC, C2 DESC,C3 ASC
and
Code:
ORDER BY C1 DESC, C2 ASC,C3 DESC
can avoid a sort right?
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri May 16, 2008 3:03 pm
Reply with quote

let' s get rid of the confusion,
whether it is an interview question or a real scenario is irrelevant
but just take a decision Yourself

just use a bit of logic

if the table has been defined with an index in descending order
Quote:
( C1 ASC, C2 DESC,C3 ASC)

and later on You run a query asking for the same column in ascending order
Quote:
(.... C2 ASC... )
,
then...
a sort will/might be performed but as usual it depends...
on other untold constraints
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri May 16, 2008 7:15 pm
Reply with quote

Hello,

Quote:
may not result a sort
I suppose it is possible that the optimizer, in some rare situation, could decide that a sort was not needed, but in general, a sort will be needed to satisfy the SELECT.

As Enrico mentioned, "other untold constraints" can have an impact.
Back to top
View user's profile Send private message
ruodeer

New User


Joined: 06 Jul 2007
Posts: 58
Location: home

PostPosted: Mon May 19, 2008 8:39 am
Reply with quote

Ok, thank you Enrico and Dick ,now I get the general idea :-)
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Rotate partition-logical & physic... DB2 0
No new posts Cobol file using index COBOL Programming 2
No new posts DB2 Statistics - Using EXPLAIN and qu... DB2 1
No new posts DL/I status code AK for GU call using... IMS DB/DC 1
No new posts DB2 Load - Sort Or order BY DB2 1
Search our Forums:

Back to Top