[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

query time

Posted on 2006-11-16
4
Medium Priority
?
420 Views
Last Modified: 2008-03-06
Hi there i was using quest and playing around and i gave it  sql to look at and run their wizard it gives me this

orginal
SELECT T1."ACCT_ID" AS "c1",
       T1."ORG_ID" AS "c2",
       T1."PROJ_ID" AS "c3",
       T1."FY_CD" AS "c4",
       T1."PD_NO" AS "c5",
       T1."S_JNL_CD" AS "c6",
       T1."POST_SEQ_NO" AS "c7",
       T2."ACCT_NAME" AS "c8",
       T3."ID" AS "c9",
       T3."AMT" AS "c10",
       T3."NAME" AS "c13",
       T3."TRN_DESC" AS "c14",
       T3."COMMENTS_NT" AS "c15",
       T1."MODIFIED_BY" AS "c16",
       T1."TIME_STAMP" AS "c17"
  FROM "UnionCP"."DELTEK"."ACCT" T2,
("UnionCP"."DELTEK"."GL_POST_SUM" T1
       LEFT OUTER JOIN "UnionCP"."DELTEK"."GL_DETL" T3
         ON T1."SRCE_KEY" = T3."GLPSUM_SRCE_KEY"
            AND T1."LVL1_KEY" = T3."GLPSUM_LVL1_KEY"
            AND T1."LVL2_KEY" = T3."GLPSUM_LVL2_KEY"
            AND T1."LVL3_KEY" = T3."GLPSUM_LVL3_KEY")
 WHERE T1."ACCT_ID" = T2."ACCT_ID"
   AND T1."ORG_ID" LIKE '1.014%'
   AND T1."PD_NO" = 1
   AND T1."ACCT_ID" LIKE '%'
 ORDER BY 6 asc


--

SELECT T1."ACCT_ID" AS "c1",
       T1."ORG_ID" AS "c2",
       T1."PROJ_ID" AS "c3",
       T1."FY_CD" AS "c4",
       T1."PD_NO" AS "c5",
       T1."S_JNL_CD" AS "c6",
       T1."POST_SEQ_NO" AS "c7",
       T2."ACCT_NAME" AS "c8",
       T3."ID" AS "c9",
       T3."AMT" AS "c10",
       T3."NAME" AS "c13",
       T3."TRN_DESC" AS "c14",
       T3."COMMENTS_NT" AS "c15",
       T1."MODIFIED_BY" AS "c16",
       T1."TIME_STAMP" AS "c17"
  FROM "UnionCP"."DELTEK"."ACCT" T2,
       "UnionCP"."DELTEK"."GL_POST_SUM" T1
       LEFT OUTER JOIN "UnionCP"."DELTEK"."GL_DETL" T3
         ON COALESCE (T1."SRCE_KEY" , T1."SRCE_KEY") = T3."GLPSUM_SRCE_KEY"
            AND T1."LVL1_KEY" = T3."GLPSUM_LVL1_KEY"
            AND T1."LVL2_KEY" = T3."GLPSUM_LVL2_KEY"
            AND T1."LVL3_KEY" = T3."GLPSUM_LVL3_KEY"
 WHERE T1."ACCT_ID" = T2."ACCT_ID"
   AND T1."ORG_ID" LIKE '1.014%'
   AND T1."PD_NO" = 1
   AND T1."ACCT_ID" LIKE '%'
 ORDER BY 6 asc
OPTION (LOOP JOIN)

I never seen the option loop join before let alone the coalesce COALESCE (T1."SRCE_KEY" , T1."SRCE_KEY") = T3."GLPSUM_SRCE_KEY"

Anyone explain what it is doing now
0
Comment
Question by:TRACEYMARY
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 17959914
>COALESCE (T1."SRCE_KEY" , T1."SRCE_KEY")
will return the value of the first parameter that is not null.
as the 2 fields are the same, this does not change anything here, except that it might influence the usage of an index on that field, ie avoid using an index on that field.


>option (loop join)
these are hints to force sql server (assumming it is sql server you use) to use a given execution plan on the join.
these options should be avoided unless you really (really really) need them and can assure that they will solve a slow-running query.
http://msdn2.microsoft.com/en-us/ms181714.aspx
0
 
LVL 3

Accepted Solution

by:
MorDeRor earned 1000 total points
ID: 17959993
well, LOOP JOIN is just a join hint. See this quote from BOL that describes this part of the OPTION clause:

{ LOOP | MERGE | HASH } JOIN

Specifies that all join operations are performed by loop join, merge join, or hash join in the whole query. If more than one join hint is specified, the optimizer selects the least expensive join strategy from the allowed ones.

If, in the same query, a join hint is also specified for a specific pair of tables, this join hint takes precedence in the joining of the two tables although the query hints still must be honored. Thus, the join hint for the pair of tables may only restrict the selection of allowed join methods in the query hint. See Hints for details.

as far as COALESCE (T1."SRCE_KEY" , T1."SRCE_KEY") = T3."GLPSUM_SRCE_KEY" - it's just T1."SRCE_KEY"=T3."GLPSUM_SRCE_KEY". I don't know what's the point of using COALESCE with a repeated expression. certainly defeats the purpuse, because you will get an error if T1."SRCE_KEY" is ever null (try "select coalesce(null,null)")
0
 
LVL 7

Author Comment

by:TRACEYMARY
ID: 17967981
Thanks i appreciate it....
0
 
LVL 3

Expert Comment

by:MorDeRor
ID: 17972872
By the way, I have a correction on what I said, about COALESCE - COALESCE (T1."SRCE_KEY" , T1."SRCE_KEY") will return a NULL when T1.SCRCE_KEY is null, not an error like I wrote before. While it is true that COALESCE(NULL,NULL) will return an error, it is for a different reason.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question