Hi All,
I am seeing a SELECT blocking a TRUNCATE statement. THE SELECT is running over 4 hours and it is waitype is AYSN_NETWORK_IO. Isolation level is default read committed isolation level.
Why or when does a SELECT takes "Sch-Sā lock? I see this lock being acquired using sp_whoisactive. Truncate is waiting for="Sch-M" lock.
How to fix this blocking?
Below are the sql stmts involved in blocking.
blocking process
=================
SELECT
"C_B_REF_ORG"."ROWID_OBJECT",
"C_B_REF_ORG"."DUNS_NMBR",
"C_B_REF_ORG"."CONTROL_OWN_TXT",
"C_B_REF_ORG"."GLBL_DUNS_NMBR",
"C_B_REF_ORG"."PARENT_DUNS",
"C_B_REF_ORG"."ORG_START_YEAR",
"C_B_REF_ORG"."PRMRY_US_SIC_CODE",
"C_B_REF_ORG"."IMPORT_IND",
"C_B_REF_ORG"."EXPORT_IND",
"C_B_REF_ORG"."MINORITY_IND",
"C_B_REF_ORG"."FEMALE_IND",
"C_B_REF_ORG"."INCORP_YEAR",
"C_B_REF_ORG"."SMALL_BUSINESS_IND",
"C_B_REF_ORG"."HQ_DUNS",
"C_B_REF_ORG"."DOMESTIC_DUNS",
"C_B_REF_ORG"."FAM_HIERARCHY_LVL",
"C_B_REF_ORG"."OUT_OF_BUS_IND",
"C_B_REF_ORG"."FAM_TREE_COUNT",
"C_B_REF_ORG"."OPS_STATUS_TXT",
"C_B_REF_ORG"."STANDALONE_IND",
CASE
WHEN "C_B_REF_ORG".STANDALONE_IND = 'true' THEN 'SINGLE LOCATION'
WHEN 0 < (SELECT Count(*)
FROM C_B_REF_ORG_FAM_ROLE
WHERE REF_ORG_ID = "C_B_REF_ORG".ROWID_OBJECT
AND Upper(FAM_ROLE_MEMBER_TXT) IN ( 'HEADQUARTERS', 'PARENT' )) THEN 'HEADQUARTERS'
WHEN 0 < (SELECT Count(*)
FROM C_B_REF_ORG_FAM_ROLE
WHERE REF_ORG_ID = "C_B_REF_ORG".ROWID_OBJECT
AND Upper(FAM_ROLE_MEMBER_TXT) IN ('BRANCH', 'DIVISION')) THEN 'BRANCH'
WHEN 0 < (SELECT Count(*)
FROM C_B_REF_ORG_FAM_ROLE
WHERE REF_ORG_ID = "C_B_REF_ORG".ROWID_OBJECT
AND FAM_ROLE_MEMBER_TXT = 'Subsidiary'
AND Upper(FAM_ROLE_MEMBER_TXT) NOT IN ('HEADQUARTERS', 'PARENT', 'BRANCH','DIVISION')) THEN 'SINGLE LOCATION'
END AS LOCATION_TYP,
CASE WHEN 0 < (SELECT Count(*)
FROM C_B_REF_ORG_FAM_ROLE
WHERE REF_ORG_ID = C_B_REF_ORG.ROWID_OBJECT AND FAM_ROLE_MEMBER_TXT='Subsidiary' and HUB_STATE_IND =1)
THEN 'Subsidiary'
END AS FAM_ROLE_MEMBER_TXT,
CASE WHEN 0 < (SELECT Count(*)
FROM C_B_REF_ORG_FAM_ROLE
WHERE REF_ORG_ID = C_B_REF_ORG.ROWID_OBJECT AND FAM_ROLE_MEMBER_TXT IN ( 'Headquarters', 'Parent' ) and HUB_STATE_IND =1)
THEN 1 ELSE 0
END AS U_IS_HQ,
"C_B_REF_ORG"."NON_MARTKETABLE_REASON_TXT"
FROM
"dbo"."C_B_REF_ORG" "C_B_REF_ORG" INNER JOIN
"dbo"."DNB_INCR_REF_ORGS" "DNB_INCR_REF_ORGS"
ON "C_B_REF_ORG"."ROWID_OBJECT" = "DNB_INCR_REF_ORGS"."REF_ORG_ID" --where duns_nmbr='116894185'
blocked process
=================
TRUNCATE TABLE "dbo"."DNB_INCR_REF_ORGS"
Thanks,
Sam
August 17, 2023 at 1:25 pm
August 17, 2023 at 2:25 pm
Are your database & the referenced tables/columns using case-sensitive collation? If not, get rid of the UPPER() functions in your where clauses to ensure sargability.
August 17, 2023 at 2:57 pm
You cannot.
Wait until the query finishes ( or cancel the query )
check the Lock compatibility matrix
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution š
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
The SELECT needs a schema-lock because it has a plan to read the table. The table structure cannot change while the SELECT is reading, hence the lock.
As Johan says, kill the query
August 20, 2023 at 5:36 am
Thanks everyone.
August 22, 2023 at 4:29 pm
This was removed by the editor as SPAM
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply