SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


performance issue


performance issue

Author
Message
ekknaveen
ekknaveen
Mr or Mrs. 500
Mr or Mrs. 500 (543 reputation)Mr or Mrs. 500 (543 reputation)Mr or Mrs. 500 (543 reputation)Mr or Mrs. 500 (543 reputation)Mr or Mrs. 500 (543 reputation)Mr or Mrs. 500 (543 reputation)Mr or Mrs. 500 (543 reputation)Mr or Mrs. 500 (543 reputation)

Group: General Forum Members
Points: 543 Visits: 343
Hi

When I am runnng the below query it is taking long time. Before it was fine but when i added or condition in the join clause in rd_market_price it is taking long time

DECLARE @JOB_ID INTEGER

exec @job_id= oss_mi_get_job_id

SELECT DISTINCT
YEAR(G.VESSEL_VOYAGE_DT) AS [YEAR]
,MONTH(G.VESSEL_VOYAGE_DT) AS [MONTH]
,g.price_dt
,G.VESSEL_VOYAGE_DT
,L.LOCAL_BENCHMARK_TXT
,BA.WEIGHTING_PRCT
,G.BENCHMARK_FLEET_CD AS VESSELCLASS
,G.SUBCLASS_GROUP_NM AS CLASS
,SC.MIS_SUB_CLASS_CD AS SUB_CLASS
,G.SUBCLASS_TXT AS VESSEL_REF
,ROUND((BA.TONS_NBR /BA.VOYAGE_DURATION_DAYS) * BA.WEIGHTING_PRCT,2) AS TONS
, L.LOCAL_BENCHMARK_VAL AS MTM
,CONVERT(VARCHAR(8), GETDATE(), 112) AS [DATE STAMP]
,G.SUBCLASS_GROUP_NM AS PRODUCT
,MIN(FPD.QUOTE_VAL) AS FREIGHT_RATE
,MIN(FOPD.QUOTE_VAL) AS BUNKER_RATE
,MIN(GOPD.QUOTE_VAL) AS DIESEL_RATE
FROM OSS_DAILY_BENCHMARK_LOCAL L
JOIN OSS_DAILY_BENCHMARK_GLOBAL G
ON L.DAILY_BENCHMARK_GLOBAL_SEQ= G.DAILY_BENCHMARK_GLOBAL_SEQ
JOIN OSS_BENCHMARK_PRICE_REFERENCE PR
ON L.DAILY_BENCHMARK_LOCAL_SEQ=PR.DAILY_BENCHMARK_LOCAL_SEQ
JOIN RD_MARKET_PRICE MP
ON MP.MARKET_PRICE_SEQ=PR.MARKET_PRICE_SEQ
OR MP.MARKET_PRICE_SEQ=PR.FUEL_MARKET_PRICE_SEQ
OR MP.MARKET_PRICE_SEQ=PR.GAS_MARKET_PRICE_SEQ
JOIN OSS_BENCHMARK_ASSUMPTION_SNAPSHOT BA
ON L.BENCHMARK_ASSUMPTION_SNAPSHOT_SEQ=BA.BENCHMARK_ASSUMPTION_SNAPSHOT_SEQ
JOIN OSS_BENCHMARK_ASSUMPTION OBA
ON OBA.BENCHMARK_ASSUMPTION_SEQ=BA.BENCHMARK_ASSUMPTION_SEQ
INNER JOIN OSS_BENCHMARK_SUBCLASS_PERIOD SP
ON SP.BENCHMARK_SUBCLASS_PERIOD_SEQ = OBA.BENCHMARK_SUBCLASS_PERIOD_SEQ
INNER JOIN OSS_BENCHMARK_SUBCLASS S
ON SP.BENCHMARK_SUBCLASS_SEQ = S.BENCHMARK_SUBCLASS_SEQ
JOIN OSS_BENCHMARK_SHIP_CONTROL sc --OSS_MIS_BENCHMARK_SHIP_CONTROL_view SC
ON SC.FULL_BENCHMARK_CD = S.SUBCLASS_NM
LEFT JOIN OSS_MARKET_PRICE_DAILY FPD
ON MP.MARKET_PRICE_SEQ=FPD.MARKET_PRICE_SEQ
AND MP.PRICE_TYPE_CD ='FREIGHT'
AND FPD.OPTIMISATION_JOB_SEQ= @JOB_ID
AND CONVERT(VARCHAR(8), FPD.APPLICABLE_DT, 112)= CONVERT(VARCHAR(8), G.price_dt, 112)
LEFT JOIN OSS_MARKET_PRICE_DAILY FOPD
ON MP.MARKET_PRICE_SEQ=FOPD.MARKET_PRICE_SEQ
AND MP.PRICE_TYPE_CD ='FUEL OIL'
AND FOPD.OPTIMISATION_JOB_SEQ= @JOB_ID
AND CONVERT(VARCHAR(8), FOPD.APPLICABLE_DT, 112)= CONVERT(VARCHAR(8), G.price_dt, 112)
LEFT JOIN OSS_MARKET_PRICE_DAILY GOPD
ON MP.MARKET_PRICE_SEQ=GOPD.MARKET_PRICE_SEQ
AND MP.PRICE_TYPE_CD ='GAS OIL'
AND GOPD.OPTIMISATION_JOB_SEQ= @JOB_ID
AND CONVERT(VARCHAR(8), GOPD.APPLICABLE_DT, 112)= CONVERT(VARCHAR(8), G.price_dt, 112)
WHERE G.SUBCLASS_DISPLAY_NM in (select vout from OSS_MI_SPLITTING (@VESSEL_REF))
AND G.VESSEL_VOYAGE_DT>=@VESSEL_VOYAGE_START_DATE AND G.VESSEL_VOYAGE_DT<=@VESSEL_VOYAGE_END_DATE
--AND G.PRICE_DT>=@VESSEL_VOYAGE_START_DATE AND G.PRICE_DT<=@VESSEL_VOYAGE_END_DATE

AND G.OPTIMISATION_JOB_SEQ=@JOB_ID
and substring(g.BENCHMARK_FLEET_CD,1,2)=substring(@VESSEL_REF,1,2)


GROUP BY YEAR(G.VESSEL_VOYAGE_DT), MONTH(G.VESSEL_VOYAGE_DT),g.price_dt ,
G.VESSEL_VOYAGE_DT,L.LOCAL_BENCHMARK_TXT,BA.WEIGHTING_PRCT,
G.BENCHMARK_FLEET_CD,G.SUBCLASS_GROUP_NM,SC.MIS_SUB_CLASS_CD,
G.SUBCLASS_TXT,BA.TONS_NBR,BA.VOYAGE_DURATION_DAYS,L.LOCAL_BENCHMARK_VAL,G.SUBCLASS_GROUP_NM
ORDER BY 3,4 DESC

Can any one help me out in this

Regards
Naveen
GilaMonster
GilaMonster
SSC Guru
SSC Guru (218K reputation)SSC Guru (218K reputation)SSC Guru (218K reputation)SSC Guru (218K reputation)SSC Guru (218K reputation)SSC Guru (218K reputation)SSC Guru (218K reputation)SSC Guru (218K reputation)

Group: General Forum Members
Points: 218875 Visits: 46279
Table definitions, index definitions and execution plan please. Also the definition of all the functns used in there will help.

Is that distinct really necessary?

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


ChrisM@Work
ChrisM@Work
SSC-Forever
SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)

Group: General Forum Members
Points: 40488 Visits: 20000
As Gail states.

You may get some mileage from this:
-- Extract this chunk of your query separately
--------------------------------------------------------------------
JOIN OSS_BENCHMARK_PRICE_REFERENCE PR
ON L.DAILY_BENCHMARK_LOCAL_SEQ=PR.DAILY_BENCHMARK_LOCAL_SEQ

JOIN RD_MARKET_PRICE MP
ON MP.MARKET_PRICE_SEQ=PR.MARKET_PRICE_SEQ
OR MP.MARKET_PRICE_SEQ=PR.FUEL_MARKET_PRICE_SEQ
OR MP.MARKET_PRICE_SEQ=PR.GAS_MARKET_PRICE_SEQ

LEFT JOIN OSS_MARKET_PRICE_DAILY FPD
ON MP.MARKET_PRICE_SEQ=FPD.MARKET_PRICE_SEQ
AND MP.PRICE_TYPE_CD ='FREIGHT'
AND FPD.OPTIMISATION_JOB_SEQ= @JOB_ID
AND CONVERT(VARCHAR(8), FPD.APPLICABLE_DT, 112)= CONVERT(VARCHAR(8), G.price_dt, 112)

LEFT JOIN OSS_MARKET_PRICE_DAILY FOPD
ON MP.MARKET_PRICE_SEQ=FOPD.MARKET_PRICE_SEQ
AND MP.PRICE_TYPE_CD ='FUEL OIL'
AND FOPD.OPTIMISATION_JOB_SEQ= @JOB_ID
AND CONVERT(VARCHAR(8), FOPD.APPLICABLE_DT, 112)= CONVERT(VARCHAR(8), G.price_dt, 112)

LEFT JOIN OSS_MARKET_PRICE_DAILY GOPD
ON MP.MARKET_PRICE_SEQ=GOPD.MARKET_PRICE_SEQ
AND MP.PRICE_TYPE_CD ='GAS OIL'
AND GOPD.OPTIMISATION_JOB_SEQ = @JOB_ID
AND CONVERT(VARCHAR(8), GOPD.APPLICABLE_DT, 112)= CONVERT(VARCHAR(8), G.price_dt, 112)
-------------------------------------------------------------------

-- something like this. Set it up either as a CTE, a derived table,
-- or (probably faster) a #temporary table
SELECT
PR.DAILY_BENCHMARK_LOCAL_SEQ,
APPLICABLE_DT = CONVERT(VARCHAR(8), FPD.APPLICABLE_DT, 112),

FREIGHT_RATE = CASE WHEN MP.PRICE_TYPE_CD ='FREIGHT' THEN FPD.QUOTE_VAL ELSE 0 END,
BUNKER_RATE = CASE WHEN MP.PRICE_TYPE_CD ='FUEL OIL' THEN FPD.QUOTE_VAL ELSE 0 END,
DIESEL_RATE = CASE WHEN MP.PRICE_TYPE_CD ='GAS OIL' THEN FPD.QUOTE_VAL ELSE 0 END

FROM OSS_BENCHMARK_PRICE_REFERENCE PR

INNER JOIN RD_MARKET_PRICE MP
ON MP.MARKET_PRICE_SEQ IN (PR.MARKET_PRICE_SEQ, PR.FUEL_MARKET_PRICE_SEQ, PR.GAS_MARKET_PRICE_SEQ)

LEFT JOIN OSS_MARKET_PRICE_DAILY FPD
ON MP.MARKET_PRICE_SEQ = FPD.MARKET_PRICE_SEQ
--AND MP.PRICE_TYPE_CD ='FREIGHT'
AND FPD.OPTIMISATION_JOB_SEQ = @JOB_ID
--AND CONVERT(VARCHAR(8), FPD.APPLICABLE_DT, 112)= CONVERT(VARCHAR(8), G.price_dt, 112)

GROUP BY
PR.DAILY_BENCHMARK_LOCAL_SEQ,
CONVERT(VARCHAR(8), FPD.APPLICABLE_DT, 112)


-- note that functions in JOINs and the WHERE clause are likely to render the search non-SARGable



“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
T.Ashish
T.Ashish
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1341 Visits: 607
select vout from OSS_MI_SPLITTING (@VESSEL_REF)

can also be shifted to CTE
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search