Click here to Skip to main content
15,891,976 members

help required tune the sql

nirkar jena asked:

Open original thread
Hi all,
Please help me to tune the below sql in sql server .taking long time while inserting.

SQL
insert into AN_MAPPING(MAPPING_ID,MAPPING_NAME,SESSION_ID,FOLDER_NAME,TOOL_ID,PROJECT_ID)
( 
select distinct mapping_id,
	mapping_name,
	session_id,
	subject_area,
	tool_id,
	PROJECT_ID
from
(
select  distinct rsm.mapping_id,
rls.mapping_name,
rls.session_id,
rls.subject_area,
1  tool_id,
A.PROJECT_ID
              from
              dbo.FD_INFA_REP_LOAD_SESSIONS rls,
              dbo.FD_INFA_REP_SRC_MAPPING rsm,
              (
SELECT distinct
 OPB_MAPPING.PROJECT_ID,
   OPB_SUBJECT.SUBJ_NAME SUBJECT_AREA,
    OPB_SUBJECT.SUBJ_ID SUBJ_ID,
    OPB_MAPPING.MAPPING_NAME MAPPING_NAME
   
FROM  dbo.FD_INFA_OPB_MAPPING OPB_MAPPING 
inner join dbo.FD_INFA_OPB_TDS OPB_TDS 
on OPB_TDS.MAPPING_ID = OPB_MAPPING.MAPPING_ID
and OPB_TDS.VERSION_NUMBER=OPB_MAPPING.VERSION_NUMBER
inner join dbo.FD_INFA_OPB_WIDGET_INST OPB_WIDGET_INST on 
OPB_WIDGET_INST.MAPPING_ID=OPB_MAPPING.MAPPING_ID 
and OPB_MAPPING.VERSION_NUMBER = OPB_WIDGET_INST.VERSION_NUMBER
inner JOIN dbo.FD_INFA_OPB_TARG OPB_TARG on 
OPB_TARG.TARGET_ID=OPB_WIDGET_INST.WIDGET_ID
inner JOIN dbo.FD_INFA_OPB_SUBJECT OPB_SUBJECT on 
OPB_SUBJECT.SUBJ_ID=OPB_TARG.SUBJ_ID
AND OPB_WIDGET_INST.WIDGET_TYPE = 2
AND OPB_MAPPING.REF_WIDGET_ID = 0
AND OPB_MAPPING.IS_VISIBLE in(1,2)
AND OPB_TARG.IS_VISIBLE in( 1,2)
AND OPB_MAPPING.PROJECT_ID= -511779242
--    AND(datediff (ss,CNTL.FN_Last_UpdateTime,OPB_MAPPING.LAST_SAVED)>0
--OR datediff (ss,CNTL.FN_Last_UpdateTime,OPB_TARG.LAST_SAVED)>0)
              ) A
 where
    rls.mapping_name = rsm.mapping_name
   and rls.SUBJECT_AREA = rsm.SUBJECT_AREA
   and  rls.IS_VALID=1
   and A.mapping_name = rls.mapping_name
   and rsm.PROJECT_ID = rls.PROJECT_ID
   and rls.PROJECT_ID = -511779242)B
   )


[Posted as solution]
in estimated execution plan i found hast match aggregate cost is taking 64%.
Tags: SQL Server

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900