SQL statement performance issues
Hi: A sql statement I have is taking too long to complete. But if I break the statement into two separate statements, it runs fine.
SQL 1 runs fine and returns 163.
SELECT /*+ FIRST_ROWS */ entity_group.entity FROM auth, entity_group, user_group WHERE entity_group.auth_group = user_group.groupid and user_group.userid = auth.id and auth.username = 'ing';
SQL 2 runs fine, prints about 20 records
select /*+ FIRST_ROWS */ EVENT_DATA.info from EVENT_DATA, AGENTS where EVENT_DATA.agent_id = agents.id AND agents.entity IN (163);
SQL 3 takes a long time to run. The field AGENT_ID is indexed in EVENT_DATA.
select /*+ FIRST_ROWS */ EVENT_DATA.info from EVENT_DATA, AGENTS where EVENT_DATA.agent_id = agents.id AND agents.entity IN (SELECT /*+ FIRST_ROWS */ entity_group.entity FROM auth, entity_group, user_group WHERE entity_group.auth_group = user_group.groupid and user_group.userid = auth.id and auth.username = 'ing');
Any suggestions on improving the SQL statement or finding out if anything is wrong with the database.
Thanks
Ravi
First, lose the hints, analyse your tables and let the CBO do its job. If it is not fast enough. then Nicolas' solution may be faster.
Another possible construct would be:
SELECT event_data.info
FROM event_data, agents,
(SELECT DISTINCT entity_group.entity
FROM auth, entity_group, user_group
WHERE entity_group.auth_group = user_group.groupid and
user_group.userid = auth.id and
auth.username = 'ing') eg
WHERE event_data.agent_id = agents.id and
agents.entity = eg.entityTTFN
John
Similar Messages
-
SQL query performance issues.
Hi All,
I worked on the query a month ago and the fix worked for me in test intance but failed in production. Following is the URL for the previous thread.
SQL query performance issues.
Following is the tkprof file.
CURSOR_ID:76 LENGTH:2383 ADDRESS:f6b40ab0 HASH_VALUE:2459471753 OPTIMIZER_GOAL:ALL_ROWS USER_ID:443 (APPS)
insert into cos_temp(
TRX_DATE, DEPT, PRODUCT_LINE, PART_NUMBER,
CUSTOMER_NUMBER, QUANTITY_SOLD, ORDER_NUMBER,
INVOICE_NUMBER, EXT_SALES, EXT_COS,
GROSS_PROFIT, ACCT_DATE,
SHIPMENT_TYPE,
FROM_ORGANIZATION_ID,
FROM_ORGANIZATION_CODE)
select a.trx_date,
g.segment5 dept,
g.segment4 prd,
m.segment1 part,
d.customer_number customer,
b.quantity_invoiced units,
-- substr(a.sales_order,1,6) order#,
substr(ltrim(b.interface_line_attribute1),1,10) order#,
a.trx_number invoice,
(b.quantity_invoiced * b.unit_selling_price) sales,
(b.quantity_invoiced * nvl(price.operand,0)) cos,
(b.quantity_invoiced * b.unit_selling_price) -
(b.quantity_invoiced * nvl(price.operand,0)) profit,
to_char(to_date('2010/02/28 00:00:00','yyyy/mm/dd HH24:MI:SS'),'DD-MON-RR') acct_date,
'DRP',
l.ship_from_org_id,
p.organization_code
from ra_customers d,
gl_code_combinations g,
mtl_system_items m,
ra_cust_trx_line_gl_dist c,
ra_customer_trx_lines b,
ra_customer_trx_all a,
apps.oe_order_lines l,
apps.HR_ORGANIZATION_INFORMATION i,
apps.MTL_INTERCOMPANY_PARAMETERS inter,
apps.HZ_CUST_SITE_USES_ALL site,
apps.qp_list_lines_v price,
apps.mtl_parameters p
where a.trx_date between to_date('2010/02/01 00:00:00','yyyy/mm/dd HH24:MI:SS')
and to_date('2010/02/28 00:00:00','yyyy/mm/dd HH24:MI:SS')+0.9999
and a.batch_source_id = 1001 -- Sales order shipped other OU
and a.complete_flag = 'Y'
and a.customer_trx_id = b.customer_trx_id
and b.customer_trx_line_id = c.customer_trx_line_id
and a.sold_to_customer_id = d.customer_id
and b.inventory_item_id = m.inventory_item_id
and m.organization_id
= decode(substr(g.segment4,1,2),'01',5004,'03',5004,
'02',5003,'00',5001,5002)
and nvl(m.item_type,'0') <> '111'
and c.code_combination_id = g.code_combination_id+0
and l.line_id = b.interface_line_attribute6
and i.organization_id = l.ship_from_org_id
and p.organization_id = l.ship_from_org_id
and i.org_information3 <> '5108'
and inter.ship_organization_id = i.org_information3
and inter.sell_organization_id = '5108'
and inter.customer_site_id = site.site_use_id
and site.price_list_id = price.list_header_id
and product_attr_value = to_char(m.inventory_item_id)
call count cpu elapsed disk query current rows misses
Parse 1 0.47 0.56 11 197 0 0 1
Execute 1 3733.40 3739.40 34893 519962154 11 188 0
total 2 3733.87 3739.97 34904 519962351 11 188 1
| Rows Row Source Operation
| ------------ ---------------------------------------------------
| 188 HASH JOIN (cr=519962149 pr=34889 pw=0 time=2607.35)
| 741 .TABLE ACCESS BY INDEX ROWID QP_PRICING_ATTRIBUTES (cr=519939426 pr=34889 pw=0 time=2457.32)
| 254644500 ..NESTED LOOPS (cr=519939265 pr=34777 pw=0 time=3819.67)
| 254643758 ...NESTED LOOPS (cr=8921833 pr=29939 pw=0 time=1274.41)
| 741 ....NESTED LOOPS (cr=50042 pr=7230 pw=0 time=11.37)
| 741 .....NESTED LOOPS (cr=48558 pr=7229 pw=0 time=11.35)
| 741 ......NESTED LOOPS (cr=47815 pr=7223 pw=0 time=11.32)
| 3237 .......NESTED LOOPS (cr=41339 pr=7223 pw=0 time=12.42)
| 3237 ........NESTED LOOPS (cr=38100 pr=7223 pw=0 time=12.39)
| 3237 .........NESTED LOOPS (cr=28296 pr=7139 pw=0 time=12.29)
| 1027 ..........NESTED LOOPS (cr=17656 pr=4471 pw=0 time=3.81)
| 1027 ...........NESTED LOOPS (cr=13537 pr=4404 pw=0 time=3.30)
| 486 ............NESTED LOOPS (cr=10873 pr=4240 pw=0 time=0.04)
| 486 .............NESTED LOOPS (cr=10385 pr=4240 pw=0 time=0.03)
| 486 ..............TABLE ACCESS BY INDEX ROWID RA_CUSTOMER_TRX_ALL (cr=9411 pr=4240 pw=0 time=0.02)
| 75253 ...............INDEX RANGE SCAN RA_CUSTOMER_TRX_N5 (cr=403 pr=285 pw=0 time=0.38)
| 486 ..............TABLE ACCESS BY INDEX ROWID HZ_CUST_ACCOUNTS (cr=974 pr=0 pw=0 time=0.01)
| 486 ...............INDEX UNIQUE SCAN HZ_CUST_ACCOUNTS_U1 (cr=488 pr=0 pw=0 time=0.01)
| 486 .............INDEX UNIQUE SCAN HZ_PARTIES_U1 (cr=488 pr=0 pw=0 time=0.01)
| 1027 ............TABLE ACCESS BY INDEX ROWID RA_CUSTOMER_TRX_LINES_ALL (cr=2664 pr=164 pw=0 time=1.95)
| 2063 .............INDEX RANGE SCAN RA_CUSTOMER_TRX_LINES_N2 (cr=1474 pr=28 pw=0 time=0.22)
| 1027 ...........TABLE ACCESS BY INDEX ROWID RA_CUST_TRX_LINE_GL_DIST_ALL (cr=4119 pr=67 pw=0 time=0.54)
| 1027 ............INDEX RANGE SCAN RA_CUST_TRX_LINE_GL_DIST_N1 (cr=3092 pr=31 pw=0 time=0.20)
| 3237 ..........TABLE ACCESS BY INDEX ROWID MTL_SYSTEM_ITEMS_B (cr=10640 pr=2668 pw=0 time=15.35)
| 3237 ...........INDEX RANGE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=2062 pr=40 pw=0 time=0.33)
| 3237 .........TABLE ACCESS BY INDEX ROWID OE_ORDER_LINES_ALL (cr=9804 pr=84 pw=0 time=0.77)
| 3237 ..........INDEX UNIQUE SCAN OE_ORDER_LINES_U1 (cr=6476 pr=47 pw=0 time=0.43)
| 3237 ........TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=3239 pr=0 pw=0 time=0.04)
| 3237 .........INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=2 pr=0 pw=0 time=0.01)
| 741 .......TABLE ACCESS BY INDEX ROWID HR_ORGANIZATION_INFORMATION (cr=6476 pr=0 pw=0 time=0.10)
| 6474 ........INDEX RANGE SCAN HR_ORGANIZATION_INFORMATIO_FK2 (cr=3239 pr=0 pw=0 time=0.03)Please help.
Regards
Ashish| 254644500 ..NESTED LOOPS (cr=519939265 pr=34777 pw=0 time=3819.67)
| 254643758 ...NESTED LOOPS (cr=8921833 pr=29939 pw=0 time=1274.41)There is no way the optimizer should choose to process that many rows using nested loops.
Either the statistics are not up to date, the data values are skewed or you have some optimizer parameter set to none default to force index access.
Please post explain plan and optimizer* parameter settings. -
New sessions every time an sql statement is issued
Hi, I have a problem with using oraoledb (v 10.1.0) with VB6 accessing an Oracle database 9i (v 9.2.0.6). Every time an sql statement is issued in the client side, a new session is started in the server side (seen in Enterprise Manager). I don´'t know why. Is an oraoledb parameter or a database parameter? How can I avoid this? The big problem behind this behaviour is controling row locking. If I issue a "select field from table where conditions for update nowait(or wait n)", this creates a lock that belongs to a session. If a few sentences after I issue an "update the-same-table set the-same-field = value where the-same-condition" as this one creates a new session, an ORA-00054 is raised telling the row(s) is blocked.
any idea?
thanksI'm a DBA and I encountered the same problem with a system developed for our company. We reported that to the company that developed the application and they sey then close the conections, but they remain in the database.
Could anyone find a solution for this? I believe is a problem in the VB code, but I do not know anything from VB.
thanks,
Lisandro -
Required info on SQL Server Performance Issue Analysis and Troubleshoot way
Dear All,
I am going to prepare the simple documentation steps on SQL Server Performance Issue Analysis and troubleshoot method. I am struggling to make this documentation since we have different checklist (like network latency,disk latency, memory/processor pressure,SQL
query tuning etc) to validate once application performance issue reported from the customer.So, I am looking for the experts document or link sharing .
Your input will help for document preparation in better way.
Thanks in advance.Hi,
Recommendations and Guidelines on configuring disk partitions for SQL Server
http://support.microsoft.com/kb/2023571
Disk and File Layout for SQL Server
https://blogs.technet.com/b/dataplatforminsider/archive/2012/12/19/disk-and-file-layout-for-sql-server.aspx
Microsoft SQL Server 2012 Performance Tuning: Implementing Physical Database Structure
http://www.packtpub.com/article/sql-server-2012-implementing-physical-database-strusture
Database Mirroring Best Practices and Performance Considerations
http://technet.microsoft.com/en-us/library/cc917681.aspx
Hope the information helps.
Tracy Cai
TechNet Community Support -
Muti sql statements execution issue with DB2 - iSeries
Hello,
I am encountering "[SQL0104] Token ; was not valid. Valid tokens: ). " error , when I execute below statement.
Using ; (semi colon) for sql statements separation.
Please let me know , how to fix it.
Thanks in advance.
<cfquery name="qInsertTo" datasource="dsn">
<cfloop from="1" to="25" index="i">
insert into test1(userId,firstname) values('xx#i#','fname#i#') ;
</cfloop>
</cfquery>
PS: I don't want to keep cfloop outside cfquery.Hi,
trhat would be possible for an Unix System ... but I'm on a Windows OS system and I already assign everybody with full modification rights ...
Thanks anyway for ur help I'll recheck it anyway sometimes its strange ...
greetings Lars -
Hey,
Please forgive me if I'm missing something really obvious but it's been a while since I did any SQL work and I'm obviously a bit rusty.
When the below query is run the CPU on the SQL server maxes out. The query itself takes over 6 hours to run.
Is there anything glaringly obvious with the query that might be causing thisCheers
Paul
SELECT TOP (100) PERCENT dbo.CUSTPACKINGSLIPTRANS.ITEMID AS [Stock Code],
dbo.CUSTPACKINGSLIPTRANS.SALESUNIT AS [Unit of Sale],
dbo.DIMENSIONFINANCIALTAG.DESCRIPTION AS [Product Group],
dbo.INVENTITEMGROUP.ITEMGROUPID AS [Item Group],
dbo.INVENTTABLE.SECTION,
dbo.INVENTTABLE.GROUPS AS [Group],
dbo.INVENTTABLE.SUBGROUPS AS [Sub Group],
dbo.CUSTPACKINGSLIPJOUR.ORDERACCOUNT AS [Cust Account],
dbo.CUSTTABLE.INVOICEACCOUNT AS [Invoice Account],
dbo.DIRPARTYTABLE.NAME AS [Cust Name],
dbo.CUSTTABLE.CURRENCY,
dbo.CUSTTABLE.CIT_CONTROLLER AS [Credit Controller],
dbo.CUSTTABLE.CREDITMAX AS [Credit Limit],
dbo.CUSTTABLE.CUSTCLASSIFICATIONID AS Classification,
dbo.DIRPERSONNAME.FIRSTNAME + ' ' + dbo.DIRPERSONNAME.LASTNAME AS [Sales Person],
dbo.SALESTABLE.SALESGROUP AS [Outside Rooms],
CASE WHEN CUSTTABLE.CUSTCLASSIFICATIONID = 'Cash' THEN dbo.SALESTABLE.SALESGROUP ELSE dbo.CUSTTABLE.SALESGROUP END AS [Sales Rep],
dbo.LOGISTICSPOSTALADDRESS.STATE [Customer Region],
dbo.LOGISTICSPOSTALADDRESS.COUNTY [Customer County],
dbo.CUSTTABLE.LINEOFBUSINESSID AS [Line Of Business],
a.DISPLAYVALUE AS [Site/Location],
dbo.CUSTPACKINGSLIPTRANS.PACKINGSLIPID AS [Delivery Ref],
dbo.LOGISTICSPOSTALADDRESS.COUNTRYREGIONID,
CONVERT(varchar(12), dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE, 111) AS [Delivery Date],
dbo.LOGISTICSPOSTALADDRESS.ADDRESS AS [Delivery Address],
dbo.CUSTPACKINGSLIPTRANS.VALUEMST AS [Delivery Value (CON)],
CONVERT(varchar(12), dbo.SALESTABLE.RECEIPTDATEREQUESTED, 111) AS [Requested Delivery Date],
dbo.SALESTABLE.SALESID AS [Order Ref],
CASE dbo.SALESTABLE.SALESSTATUS WHEN '0' THEN 'None' WHEN '1' THEN 'Open Order' WHEN '2' THEN 'Delivered' WHEN '3' THEN 'Invoiced' WHEN '4' THEN 'Canceled' END AS [Sales Status],
CASE dbo.SALESTABLE.SALESTYPE WHEN '0' THEN 'Journal' WHEN '1' THEN 'Quotation' WHEN '2' THEN 'Subscription' WHEN '3' THEN 'Sales Order' WHEN '4' THEN 'Returned Item' WHEN '5' THEN 'Blanket Order' WHEN '6' THEN 'Item Requirements' WHEN '7' THEN 'Undefined' END AS [Sales Type],
CASE dbo.SALESTABLE.AG_SALESLOCATION WHEN '0' THEN 'None' WHEN '1' THEN 'OR_DGN' WHEN '2' THEN 'OR_FMT' WHEN '3' THEN 'OR_TME' WHEN '4' THEN 'OR_OMA' WHEN '5' THEN 'DSP_DGN' WHEN '6' THEN 'DSP_FMT' WHEN '7' THEN 'DSP_TME' WHEN '8' THEN 'DSP_OMA' WHEN '9' THEN 'DSP_BEL' WHEN '10' THEN 'DSP_CDF' WHEN '11' THEN 'DSP_BGY' WHEN '12' THEN 'Credit Control' WHEN '13' THEN 'Internal Sales' WHEN '14' THEN 'CP_FMT' WHEN '15' THEN 'GBSales' END AS [Sales Location],
dbo.SALESTABLE.PURCHORDERFORMNUM AS [Customer Requisition],
dbo.SALESLINE.LINEDISC AS [Line Disc],
dbo.SALESLINE.LINEPERCENT AS [Line Percent],
dbo.SALESLINE.PRICEGROUPID AS [Price Group],
dbo.INVENTDIM.INVENTLOCATIONID AS Warehouse,
dbo.DIRPARTYTABLE.NAMEALIAS AS [Search Name],
dbo.CUSTPACKINGSLIPJOUR.LORRYID AS [Lorry ID],
dbo.CUSTPACKINGSLIPJOUR.LORRYREGNO AS [Lorry Reg],
dbo.CUSTPACKINGSLIPJOUR.LORRYDRIVER AS [Lorry Driver],
CASE dbo.SALESLINE.BLOCKED WHEN '0' THEN 'No' WHEN '1' THEN 'Yes' END AS [Stopped?],
dbo.CUSTPACKINGSLIPTRANS.QTY AS [Qty Delivered],
dbo.SALESLINE.SALESPRICE AS [Unit Price],
dbo.CUSTPACKINGSLIPJOUR.CREATEDBY AS [SDN Creator],
MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS Month,
YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS Year,
DATEPART(week, dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS WeekNo,
CASE MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) WHEN '1' THEN '10' WHEN '2' THEN '11' WHEN '3' THEN '12' WHEN '4' THEN '1' WHEN '5' THEN '2' WHEN '6' THEN '3' WHEN '7' THEN '4' WHEN '8' THEN '5' WHEN '9' THEN '6' WHEN '10' THEN '7' WHEN '11' THEN '8' WHEN '12' THEN '9' END AS [Fin Period], CASE WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) <= '3' THEN CONVERT(VARCHAR(10), (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) - 1)) + '/' + CONVERT(VARCHAR(10), YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE)) WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) >= '4' THEN CONVERT(VARCHAR(10), YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE)) + '/' + CONVERT(VARCHAR(10), (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) + 1)) END AS [Fin Year],
CASE WHEN dbo.custpackingsliptrans.salesunit = '100' THEN dbo.CUSTPACKINGSLIPTRANS.SALESUNIT * dbo.CUSTPACKINGSLIPTRANS.QTY WHEN dbo.custpackingsliptrans.salesunit = '1000' THEN dbo.CUSTPACKINGSLIPTRANS.SALESUNIT * dbo.CUSTPACKINGSLIPTRANS.QTY ELSE dbo.CUSTPACKINGSLIPTRANS.QTY END AS [No of Units],
CASE dbo.INVENTITEMGROUPITEM.ITEMGROUPID WHEN 'Mortar' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Sand' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Decorative Gravel' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Crushed Aggregates' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Lintels' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 WHEN 'TBeams' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 WHEN 'Aggregates' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Lime' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY * dbo.UNITOFMEASURECONVERSION.FACTOR) WHEN 'Readymix' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 ELSE (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY * dbo.UNITOFMEASURECONVERSION.FACTOR) / 1000 END AS Tonnage,
dbo.INVENTTABLE.NETWEIGHT AS [Net Weight],
dbo.INVENTTABLE.PRODCOSTA,
dbo.INVENTTABLE.PRODCOSTB,
dbo.INVENTTABLE.PRODCOSTC,
dbo.INVENTTABLE.PRODCOSTD,
dbo.INVENTTABLE.PRODCOSTE,
dbo.INVENTTABLE.PRODCOSTF,
dbo.INVENTTABLE.PRODCOSTG,
dbo.INVENTTABLE.PRODCOSTH,
dbo.INVENTTABLE.QTYPERBALE,
dbo.INVENTTABLE.M2PERBALE,
dbo.SALESTABLE.SALESTYPE,
dbo.SALESTABLE.DLVMODE AS [Delivery Mode],
CONVERT(varchar(12), dbo.SALESTABLE.SHIPPINGDATECONFIRMED, 111) AS [Shipping Date Confirmed],
CONVERT(varchar(12), dbo.SALESTABLE.CREATEDDATETIME, 111) AS [Created Date],
dbo.SALESLINE.CUSTGROUP AS [Cust Group],
dbo.INVENTTABLE.MADETOORDER AS [Made To Order]
FROM dbo.CUSTPACKINGSLIPTRANS INNER JOIN
dbo.CUSTPACKINGSLIPJOUR ON dbo.CUSTPACKINGSLIPTRANS.PACKINGSLIPID = dbo.CUSTPACKINGSLIPJOUR.PACKINGSLIPID INNER JOIN
dbo.SALESLINE ON dbo.CUSTPACKINGSLIPJOUR.SALESID = dbo.SALESLINE.SALESID AND
dbo.CUSTPACKINGSLIPTRANS.INVENTTRANSID = dbo.SALESLINE.INVENTTRANSID INNER JOIN
dbo.INVENTTABLE ON dbo.CUSTPACKINGSLIPTRANS.ITEMID = dbo.INVENTTABLE.ITEMID INNER JOIN
dbo.INVENTITEMGROUPITEM ON dbo.INVENTTABLE.ITEMID = dbo.INVENTITEMGROUPITEM.ITEMID INNER JOIN
dbo.INVENTITEMGROUP ON dbo.INVENTITEMGROUPITEM.ITEMGROUPID = dbo.INVENTITEMGROUP.ITEMGROUPID INNER JOIN
dbo.INVENTDIM ON dbo.SALESLINE.INVENTDIMID = dbo.INVENTDIM.INVENTDIMID INNER JOIN
dbo.CUSTTABLE ON dbo.CUSTPACKINGSLIPJOUR.ORDERACCOUNT = dbo.CUSTTABLE.ACCOUNTNUM INNER JOIN
dbo.DIRPARTYTABLE ON dbo.CUSTTABLE.PARTY = dbo.DIRPARTYTABLE.RECID INNER JOIN
dbo.LOGISTICSPOSTALADDRESS ON dbo.DIRPARTYTABLE.PRIMARYADDRESSLOCATION = dbo.LOGISTICSPOSTALADDRESS.LOCATION INNER JOIN
dbo.SALESTABLE ON dbo.SALESLINE.SALESID = dbo.SALESTABLE.SALESID INNER JOIN
dbo.DIRPERSONNAME ON dbo.SALESTABLE.WORKERSALESTAKER = dbo.DIRPERSONNAME.RECID INNER JOIN
dbo.ECORESPRODUCT ON dbo.CUSTPACKINGSLIPTRANS.ITEMID = dbo.ECORESPRODUCT.SEARCHNAME
AND dbo.INVENTTABLE.ITEMID = dbo.ECORESPRODUCT.DISPLAYPRODUCTNUMBER LEFT OUTER JOIN
dbo.UNITOFMEASURECONVERSION ON dbo.ECORESPRODUCT.RECID = dbo.UNITOFMEASURECONVERSION.PRODUCT LEFT OUTER JOIN
dbo.UNITOFMEASURE ON dbo.UNITOFMEASURECONVERSION.TOUNITOFMEASURE = dbo.UNITOFMEASURE.RECID INNER JOIN
dbo.DEFAULTDIMENSIONVIEW a ON dbo.CUSTPACKINGSLIPTRANS.DEFAULTDIMENSION = a.DEFAULTDIMENSION AND a.NAME = 'Department' LEFT OUTER JOIN
dbo.DEFAULTDIMENSIONVIEW b ON dbo.INVENTTABLE.DEFAULTDIMENSION = b.DEFAULTDIMENSION AND b.NAME = 'Center' INNER JOIN
dbo.DIMENSIONFINANCIALTAG ON b.ENTITYINSTANCE = dbo.DIMENSIONFINANCIALTAG.RECID
WHERE (dbo.CUSTPACKINGSLIPTRANS.DATAAREAID = 'agl') AND
(dbo.CUSTPACKINGSLIPJOUR.DATAAREAID = 'agl') AND
(dbo.SALESLINE.DATAAREAID = 'agl') AND
(dbo.INVENTTABLE.DATAAREAID = 'vuk') AND
(dbo.INVENTDIM.DATAAREAID = 'agl') AND
(dbo.CUSTTABLE.DATAAREAID = 'agl') AND
(dbo.SALESTABLE.DATAAREAID = 'agl') AND
(CASE WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) <= '3' THEN (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) - 1)
WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) >= '4' THEN YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) END = 2014)Hey,
Please forgive me if I'm missing something really obvious but it's been a while since I did any SQL work and I'm obviously a bit rusty.
When the below query is run the CPU on the SQL server maxes out. The query itself takes over 6 hours to run.
Is there anything glaringly obvious with the query that might be causing thisCheers
Paul
SELECT TOP (100) PERCENT dbo.CUSTPACKINGSLIPTRANS.ITEMID AS [Stock Code],
dbo.CUSTPACKINGSLIPTRANS.SALESUNIT AS [Unit of Sale],
dbo.DIMENSIONFINANCIALTAG.DESCRIPTION AS [Product Group],
dbo.INVENTITEMGROUP.ITEMGROUPID AS [Item Group],
dbo.INVENTTABLE.SECTION,
dbo.INVENTTABLE.GROUPS AS [Group],
dbo.INVENTTABLE.SUBGROUPS AS [Sub Group],
dbo.CUSTPACKINGSLIPJOUR.ORDERACCOUNT AS [Cust Account],
dbo.CUSTTABLE.INVOICEACCOUNT AS [Invoice Account],
dbo.DIRPARTYTABLE.NAME AS [Cust Name],
dbo.CUSTTABLE.CURRENCY,
dbo.CUSTTABLE.CIT_CONTROLLER AS [Credit Controller],
dbo.CUSTTABLE.CREDITMAX AS [Credit Limit],
dbo.CUSTTABLE.CUSTCLASSIFICATIONID AS Classification,
dbo.DIRPERSONNAME.FIRSTNAME + ' ' + dbo.DIRPERSONNAME.LASTNAME AS [Sales Person],
dbo.SALESTABLE.SALESGROUP AS [Outside Rooms],
CASE WHEN CUSTTABLE.CUSTCLASSIFICATIONID = 'Cash' THEN dbo.SALESTABLE.SALESGROUP ELSE dbo.CUSTTABLE.SALESGROUP END AS [Sales Rep],
dbo.LOGISTICSPOSTALADDRESS.STATE [Customer Region],
dbo.LOGISTICSPOSTALADDRESS.COUNTY [Customer County],
dbo.CUSTTABLE.LINEOFBUSINESSID AS [Line Of Business],
a.DISPLAYVALUE AS [Site/Location],
dbo.CUSTPACKINGSLIPTRANS.PACKINGSLIPID AS [Delivery Ref],
dbo.LOGISTICSPOSTALADDRESS.COUNTRYREGIONID,
CONVERT(varchar(12), dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE, 111) AS [Delivery Date],
dbo.LOGISTICSPOSTALADDRESS.ADDRESS AS [Delivery Address],
dbo.CUSTPACKINGSLIPTRANS.VALUEMST AS [Delivery Value (CON)],
CONVERT(varchar(12), dbo.SALESTABLE.RECEIPTDATEREQUESTED, 111) AS [Requested Delivery Date],
dbo.SALESTABLE.SALESID AS [Order Ref],
CASE dbo.SALESTABLE.SALESSTATUS WHEN '0' THEN 'None' WHEN '1' THEN 'Open Order' WHEN '2' THEN 'Delivered' WHEN '3' THEN 'Invoiced' WHEN '4' THEN 'Canceled' END AS [Sales Status],
CASE dbo.SALESTABLE.SALESTYPE WHEN '0' THEN 'Journal' WHEN '1' THEN 'Quotation' WHEN '2' THEN 'Subscription' WHEN '3' THEN 'Sales Order' WHEN '4' THEN 'Returned Item' WHEN '5' THEN 'Blanket Order' WHEN '6' THEN 'Item Requirements' WHEN '7' THEN 'Undefined' END AS [Sales Type],
CASE dbo.SALESTABLE.AG_SALESLOCATION WHEN '0' THEN 'None' WHEN '1' THEN 'OR_DGN' WHEN '2' THEN 'OR_FMT' WHEN '3' THEN 'OR_TME' WHEN '4' THEN 'OR_OMA' WHEN '5' THEN 'DSP_DGN' WHEN '6' THEN 'DSP_FMT' WHEN '7' THEN 'DSP_TME' WHEN '8' THEN 'DSP_OMA' WHEN '9' THEN 'DSP_BEL' WHEN '10' THEN 'DSP_CDF' WHEN '11' THEN 'DSP_BGY' WHEN '12' THEN 'Credit Control' WHEN '13' THEN 'Internal Sales' WHEN '14' THEN 'CP_FMT' WHEN '15' THEN 'GBSales' END AS [Sales Location],
dbo.SALESTABLE.PURCHORDERFORMNUM AS [Customer Requisition],
dbo.SALESLINE.LINEDISC AS [Line Disc],
dbo.SALESLINE.LINEPERCENT AS [Line Percent],
dbo.SALESLINE.PRICEGROUPID AS [Price Group],
dbo.INVENTDIM.INVENTLOCATIONID AS Warehouse,
dbo.DIRPARTYTABLE.NAMEALIAS AS [Search Name],
dbo.CUSTPACKINGSLIPJOUR.LORRYID AS [Lorry ID],
dbo.CUSTPACKINGSLIPJOUR.LORRYREGNO AS [Lorry Reg],
dbo.CUSTPACKINGSLIPJOUR.LORRYDRIVER AS [Lorry Driver],
CASE dbo.SALESLINE.BLOCKED WHEN '0' THEN 'No' WHEN '1' THEN 'Yes' END AS [Stopped?],
dbo.CUSTPACKINGSLIPTRANS.QTY AS [Qty Delivered],
dbo.SALESLINE.SALESPRICE AS [Unit Price],
dbo.CUSTPACKINGSLIPJOUR.CREATEDBY AS [SDN Creator],
MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS Month,
YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS Year,
DATEPART(week, dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS WeekNo,
CASE MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) WHEN '1' THEN '10' WHEN '2' THEN '11' WHEN '3' THEN '12' WHEN '4' THEN '1' WHEN '5' THEN '2' WHEN '6' THEN '3' WHEN '7' THEN '4' WHEN '8' THEN '5' WHEN '9' THEN '6' WHEN '10' THEN '7' WHEN '11' THEN '8' WHEN '12' THEN '9' END AS [Fin Period], CASE WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) <= '3' THEN CONVERT(VARCHAR(10), (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) - 1)) + '/' + CONVERT(VARCHAR(10), YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE)) WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) >= '4' THEN CONVERT(VARCHAR(10), YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE)) + '/' + CONVERT(VARCHAR(10), (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) + 1)) END AS [Fin Year],
CASE WHEN dbo.custpackingsliptrans.salesunit = '100' THEN dbo.CUSTPACKINGSLIPTRANS.SALESUNIT * dbo.CUSTPACKINGSLIPTRANS.QTY WHEN dbo.custpackingsliptrans.salesunit = '1000' THEN dbo.CUSTPACKINGSLIPTRANS.SALESUNIT * dbo.CUSTPACKINGSLIPTRANS.QTY ELSE dbo.CUSTPACKINGSLIPTRANS.QTY END AS [No of Units],
CASE dbo.INVENTITEMGROUPITEM.ITEMGROUPID WHEN 'Mortar' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Sand' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Decorative Gravel' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Crushed Aggregates' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Lintels' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 WHEN 'TBeams' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 WHEN 'Aggregates' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Lime' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY * dbo.UNITOFMEASURECONVERSION.FACTOR) WHEN 'Readymix' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 ELSE (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY * dbo.UNITOFMEASURECONVERSION.FACTOR) / 1000 END AS Tonnage,
dbo.INVENTTABLE.NETWEIGHT AS [Net Weight],
dbo.INVENTTABLE.PRODCOSTA,
dbo.INVENTTABLE.PRODCOSTB,
dbo.INVENTTABLE.PRODCOSTC,
dbo.INVENTTABLE.PRODCOSTD,
dbo.INVENTTABLE.PRODCOSTE,
dbo.INVENTTABLE.PRODCOSTF,
dbo.INVENTTABLE.PRODCOSTG,
dbo.INVENTTABLE.PRODCOSTH,
dbo.INVENTTABLE.QTYPERBALE,
dbo.INVENTTABLE.M2PERBALE,
dbo.SALESTABLE.SALESTYPE,
dbo.SALESTABLE.DLVMODE AS [Delivery Mode],
CONVERT(varchar(12), dbo.SALESTABLE.SHIPPINGDATECONFIRMED, 111) AS [Shipping Date Confirmed],
CONVERT(varchar(12), dbo.SALESTABLE.CREATEDDATETIME, 111) AS [Created Date],
dbo.SALESLINE.CUSTGROUP AS [Cust Group],
dbo.INVENTTABLE.MADETOORDER AS [Made To Order]
FROM dbo.CUSTPACKINGSLIPTRANS INNER JOIN
dbo.CUSTPACKINGSLIPJOUR ON dbo.CUSTPACKINGSLIPTRANS.PACKINGSLIPID = dbo.CUSTPACKINGSLIPJOUR.PACKINGSLIPID INNER JOIN
dbo.SALESLINE ON dbo.CUSTPACKINGSLIPJOUR.SALESID = dbo.SALESLINE.SALESID AND
dbo.CUSTPACKINGSLIPTRANS.INVENTTRANSID = dbo.SALESLINE.INVENTTRANSID INNER JOIN
dbo.INVENTTABLE ON dbo.CUSTPACKINGSLIPTRANS.ITEMID = dbo.INVENTTABLE.ITEMID INNER JOIN
dbo.INVENTITEMGROUPITEM ON dbo.INVENTTABLE.ITEMID = dbo.INVENTITEMGROUPITEM.ITEMID INNER JOIN
dbo.INVENTITEMGROUP ON dbo.INVENTITEMGROUPITEM.ITEMGROUPID = dbo.INVENTITEMGROUP.ITEMGROUPID INNER JOIN
dbo.INVENTDIM ON dbo.SALESLINE.INVENTDIMID = dbo.INVENTDIM.INVENTDIMID INNER JOIN
dbo.CUSTTABLE ON dbo.CUSTPACKINGSLIPJOUR.ORDERACCOUNT = dbo.CUSTTABLE.ACCOUNTNUM INNER JOIN
dbo.DIRPARTYTABLE ON dbo.CUSTTABLE.PARTY = dbo.DIRPARTYTABLE.RECID INNER JOIN
dbo.LOGISTICSPOSTALADDRESS ON dbo.DIRPARTYTABLE.PRIMARYADDRESSLOCATION = dbo.LOGISTICSPOSTALADDRESS.LOCATION INNER JOIN
dbo.SALESTABLE ON dbo.SALESLINE.SALESID = dbo.SALESTABLE.SALESID INNER JOIN
dbo.DIRPERSONNAME ON dbo.SALESTABLE.WORKERSALESTAKER = dbo.DIRPERSONNAME.RECID INNER JOIN
dbo.ECORESPRODUCT ON dbo.CUSTPACKINGSLIPTRANS.ITEMID = dbo.ECORESPRODUCT.SEARCHNAME
AND dbo.INVENTTABLE.ITEMID = dbo.ECORESPRODUCT.DISPLAYPRODUCTNUMBER LEFT OUTER JOIN
dbo.UNITOFMEASURECONVERSION ON dbo.ECORESPRODUCT.RECID = dbo.UNITOFMEASURECONVERSION.PRODUCT LEFT OUTER JOIN
dbo.UNITOFMEASURE ON dbo.UNITOFMEASURECONVERSION.TOUNITOFMEASURE = dbo.UNITOFMEASURE.RECID INNER JOIN
dbo.DEFAULTDIMENSIONVIEW a ON dbo.CUSTPACKINGSLIPTRANS.DEFAULTDIMENSION = a.DEFAULTDIMENSION AND a.NAME = 'Department' LEFT OUTER JOIN
dbo.DEFAULTDIMENSIONVIEW b ON dbo.INVENTTABLE.DEFAULTDIMENSION = b.DEFAULTDIMENSION AND b.NAME = 'Center' INNER JOIN
dbo.DIMENSIONFINANCIALTAG ON b.ENTITYINSTANCE = dbo.DIMENSIONFINANCIALTAG.RECID
WHERE (dbo.CUSTPACKINGSLIPTRANS.DATAAREAID = 'agl') AND
(dbo.CUSTPACKINGSLIPJOUR.DATAAREAID = 'agl') AND
(dbo.SALESLINE.DATAAREAID = 'agl') AND
(dbo.INVENTTABLE.DATAAREAID = 'vuk') AND
(dbo.INVENTDIM.DATAAREAID = 'agl') AND
(dbo.CUSTTABLE.DATAAREAID = 'agl') AND
(dbo.SALESTABLE.DATAAREAID = 'agl') AND
(CASE WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) <= '3' THEN (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) - 1)
WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) >= '4' THEN YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) END = 2014)
Try to minimize joins using intermediary tables, also you can consider limiting data based on date ranges and codes (DATAAREAID) before joining with other tables. -
SQL Server Performance Issue in Memory
Dear All
Can you please help me out of this below issue.
My Server having : Windows 2012 SD 64 bit
SQL : SQL 2008 R2 64 bit SP1
Memory : 64 GB
SQL Min Memory : 45 GB and Max memory : 55 GB so remaining 9 GB available
but my sql server any time shows 94% memory utilization. i have checked below points
Physical Memory_MB Physical Memory_GB Virtual Memory GB
65536 64 8192
Buffer Pool Usage at the Moment
BPool_Committed_MB BPool_Commit_Tgt_MB BPool_Visible_MB
56320.000000 56320.000000 56320.000000
Total Memory used by SQL Server Buffer Pool as reported by Perfmon counters
Mem_KB Mem_MB Mem_GB
57671680 56320.000000 55.000000000
Memory needed as per current Workload for SQL Server instance
Mem_KB Mem_MB Mem_GB
57671680 56320.000000 55.000000000
Total amount of dynamic memory the server is using for maintaining connections
Mem_KB Mem_MB Mem_GB
912 0.890625 0.000869750
Total amount of dynamic memory the server is using for locks
Mem_KB Mem_MB Mem_GB
40296 39.351562 0.038429260
Total amount of dynamic memory the server is using for the dynamic SQL cache
Mem_KB Mem_MB Mem_GB
2056 2.007812 0.001960754
Total amount of dynamic memory the server is using for query optimization
Mem_KB Mem_MB Mem_GB
2880 2.812500 0.002746582
Total amount of dynamic memory used for hash, sort and create index operations.
Mem_KB Mem_MB Mem_GB
0 0.000000 0.000000000
Total Amount of memory consumed by cursors
Mem_KB Mem_MB Mem_GB
28464 27.796875 0.027145385
Number of pages in the buffer pool (includes database, free, and stolen).
8KB_Pages Pages_in_KB Pages_in_MB
7208960 57671680.000000 56320.000000000
Number of Data pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
6710944 53687552.000000 52429.250000000
Number of Free pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
234598 1876784.000000 1832.796875000
Number of Reserved pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
0 0.000000 0.000000000
Number of Stolen pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
263418 2107344.000000 2057.953125000
Number of Plan Cache pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
135772 1086176.000000 1060.718750000
Page Life Expectancy - Number of seconds a page will stay in the buffer pool without references
Page Life in seconds PLE Status
111450 PLE is Healthy
Number of requests per second that had to wait for a free page
Free list stalls/sec
373
Number of pages flushed to disk/sec by a checkpoint or other operation that require all dirty pages to be flushed
Checkpoint pages/sec
8052165
Number of buffers written per second by the buffer manager"s lazy writer
Lazy writes/sec
1247
Total number of processes waiting for a workspace memory grant
Memory Grants Pending
0
Total number of processes that have successfully acquired a workspace memory grant
Memory Grants Outstanding
0
My User asking how much sql transaction takes out off 55 GB , and each transaction how much takes, how to find sql healthy and sql needs how much memory.
Thanks
Mohamed UdhumanIssue i mentioned here, Memory bottleneck is available or not , how to avoid sql buffer pool takes more memory means.
Thanks
Mohamed Udhuman
Hello,
Your output you posted does not makes sense or may be I am not able to understand it..If you want through analysis I need following from you
1.
select
(physical_memory_in_use_kb/1024)Memory_usedby_Sqlserver_MB,
(locked_page_allocations_kb/1024 )Locked_pages_used_Sqlserver_MB,
(total_virtual_address_space_kb/1024 )Total_VAS_in_MB,
process_physical_memory_low,
process_virtual_memory_low
from sys. dm_os_process_memory
2 What is reason for keeping Max server memory and Min server mmory almost equal. 55 G is MAX and 45 G is min.
3. Does SQL server account has locked pages in memory privilege ?
4. Did you see any out of memory error ?
5 Please post output of DBCC MEMORYSTATUS and SP_readerrorlog on skydrive and post location here.
PS: SQL server utilizing memory is normal behavior ,what you posted does not exactly points to memory pressure and what seems to me cause here is poorly written queries running.
Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers
My TechNet Wiki Articles -
DELETE statement performance issue
Dear all,
I ahve the following problem:
When running the delete script bellow:
DELETE FROM aux_exist_relationship_3 aer_3
WHERE EXISTS (SELECT ''
FROM aux_kind_of_control_1 akc_1
WHERE aer_3.cons_rel_id_new= akc_1.cons_rel_id)
AND NOT EXISTS (SELECT ''
FROM aux_kind_of_control_3 akc_3
WHERE akc_3.cons_rel_id=aer_3.cons_rel_id_new)
it takes more than 50 mins to excute it, despite there are indexes on the 3 used tables, on the three fields akc_1.cons_rel_id,akc_3.cons_rel_id and aer_3.cons_rel_id_new
Can someone advise me how to solve the issue?How many rows do you expect to delete?
You can tryDELETE FROM aux_exist_relationship_3 aer_3
WHERE aer_3.cons_rel_id_new IN(SELECT akc_1.cons_rel_id
FROM aux_kind_of_control_1 akc_1
MINUS
SELECT akc_3.cons_rel_id
FROM aux_kind_of_control_3 akc_3)Urs -
Udate SQL statement fomat issue...
Hello. I am trying to build an SQL UPDATE stmnt. , where i am using a record set to update a table. I am new to Java - I am/was able to create (separte) INSERT and DELETE SQL/CLASSES. The syntax on the Update is giving me problems (because i am a "grasshopper" no doubt). Here is the code( along with the editor errors):
String sInsertStmt;
sInsertStmt = "UPDATE cen572.vwebitem_test SET waurlc = "' rs2.getString("WAURLC") '"
CLE0001W String literals must end before the end of the source line.
WHERE WAITEMG = rs2.getString("WAITEMG")";
CLE0001W String literals must end before the end of the source line.
Thank you in advance for any tips/help that you might have to offer, i greatly appreciate it.thanks again. What if i want to update multy. fields - would this work:
System.out.println (rs2.getString("WAITEMG")); /* try this*/
String sUpdateStmt;
sUpdateStmt = "UPDATE cen572.vwebitem_test SET waurlc = '" + rs2.getString("WAURLC") + "'
SET waurli = '" + rs2.getString("WAURLI") + "'
SET waleadf = '" + rs2.getString("WALEADF") + "'";.
I seem to get error messages. I need to update multy fields. Thank you (all) again for your input, it is greatly appreciated. -
RE: Case 59063: performance issues w/ C TLIB and Forte3M
Hi James,
Could you give me a call, I am at my desk.
I had meetings all day and couldn't respond to your calls earlier.
-----Original Message-----
From: James Min [mailto:jminbrio.forte.com]
Sent: Thursday, March 30, 2000 2:50 PM
To: Sharma, Sandeep; Pyatetskiy, Alexander
Cc: sophiaforte.com; kenlforte.com; Tenerelli, Mike
Subject: Re: Case 59063: performance issues w/ C TLIB and Forte 3M
Hello,
I just want to reiterate that we are very committed to working on
this issue, and that our goal is to find out the root of the problem. But
first I'd like to narrow down the avenues by process of elimination.
Open Cursor is something that is commonly used in today's RDBMS. I
know that you must test your query in ISQL using some kind of execute
immediate, but Sybase should be able to handle an open cursor. I was
wondering if your Sybase expert commented on the fact that the server is
not responding to commonly used command like 'open cursor'. According to
our developer, we are merely following the API from Sybase, and open cursor
is not something that particularly slows down a query for several minutes
(except maybe the very first time). The logs show that Forte is waiting for
a status from the DB server. Actually, using prepared statements and open
cursor ends up being more efficient in the long run.
Some questions:
1) Have you tried to do a prepared statement with open cursor in your ISQL
session? If so, did it have the same slowness?
2) How big is the table you are querying? How many rows are there? How many
are returned?
3) When there is a hang in Forte, is there disk-spinning or CPU usage in
the database server side? On the Forte side? Absolutely no activity at all?
We actually have a Sybase set-up here, and if you wish, we could test out
your database and Forte PEX here. Since your queries seems to be running
off of only one table, this might be the best option, as we could look at
everything here, in house. To do this:
a) BCP out the data into a flat file. (character format to make it portable)
b) we need a script to create the table and indexes.
c) the Forte PEX file of the app to test this out.
d) the SQL staement that you issue in ISQL for comparison.
If the situation warrants, we can give a concrete example of
possible errors/bugs to a developer. Dial-in is still an option, but to be
able to look at the TOOL code, database setup, etc. without the limitations
of dial-up may be faster and more efficient. Please let me know if you can
provide this, as well as the answers to the above questions, or if you have
any questions.
Regards,
At 08:05 AM 3/30/00 -0500, Sharma, Sandeep wrote:
James, Ken:
FYI, see attached response from our Sybase expert, Dani Sasmita. She has
already tried what you suggested and results are enclosed.
++
Sandeep
-----Original Message-----
From: SASMITA, DANIAR
Sent: Wednesday, March 29, 2000 6:43 PM
To: Pyatetskiy, Alexander
Cc: Sharma, Sandeep; Tenerelli, Mike
Subject: Re: FW: Case 59063: Select using LIKE has performance
issues
w/ CTLIB and Forte 3M
We did that trick already.
When it is hanging, I can see what is doing.
It is doing OPEN CURSOR. But not clear the exact statement of the cursor
it is trying to open.
When we run the query directly to Sybase, not using Forte, it is clearly
not opening any cursor.
And running it directly to Sybase many times, the response is always
consistently fast.
It is just when the query runs from Forte to Sybase, it opens a cursor.
But again, in the Forte code, Alex is not using any cursor.
In trying to capture the query,we even tried to audit any statementcoming
to Sybase. Same thing, just open cursor. No cursor declaration anywhere.==============================================
James Min
Technical Support Engineer - Forte Tools
Sun Microsystems, Inc.
1800 Harrison St., 17th Fl.
Oakland, CA 94612
james.minsun.com
510.869.2056
==============================================
Support Hotline: 510-451-5400
CUSTOMERS open a NEW CASE with Technical Support:
http://www.forte.com/support/case_entry.html
CUSTOMERS view your cases and enter follow-up transactions:
http://www.forte.com/support/view_calls.htmlEarthlink wrote:
Contrary to my understanding, the <font face="courier">with_pipeline</font> procedure runs 6 time slower than the legacy <font face="courier">no_pipeline</font> procedure. Am I missing something? Well, we're missing a lot here.
Like:
- a database version
- how did you test
- what data do you have, how is it distributed, indexed
and so on.
If you want to find out what's going on then use a TRACE with wait events.
All nessecary steps are explained in these threads:
HOW TO: Post a SQL statement tuning request - template posting
http://oracle-randolf.blogspot.com/2009/02/basic-sql-statement-performance.html
Another nice one is RUNSTATS:
http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551378329289980701 -
Performance issues with pipelined table functions
I am testing pipelined table functions to be able to re-use the <font face="courier">base_query</font> function. Contrary to my understanding, the <font face="courier">with_pipeline</font> procedure runs 6 time slower than the legacy <font face="courier">no_pipeline</font> procedure. Am I missing something? The <font face="courier">processor</font> function is from [url http://www.oracle-developer.net/display.php?id=429]improving performance with pipelined table functions .
Edit: The underlying query returns 500,000 rows in about 3 minutes. So there are are no performance issues with the query itself.
Many thanks in advance.
CREATE OR REPLACE PACKAGE pipeline_example
IS
TYPE resultset_typ IS REF CURSOR;
TYPE row_typ IS RECORD (colC VARCHAR2(200), colD VARCHAR2(200), colE VARCHAR2(200));
TYPE table_typ IS TABLE OF row_typ;
FUNCTION base_query (argA IN VARCHAR2, argB IN VARCHAR2)
RETURN resultset_typ;
c_default_limit CONSTANT PLS_INTEGER := 100;
FUNCTION processor (
p_source_data IN resultset_typ,
p_limit_size IN PLS_INTEGER DEFAULT c_default_limit)
RETURN table_typ
PIPELINED
PARALLEL_ENABLE(PARTITION p_source_data BY ANY);
PROCEDURE with_pipeline (argA IN VARCHAR2,
argB IN VARCHAR2,
o_resultset OUT resultset_typ);
PROCEDURE no_pipeline (argA IN VARCHAR2,
argB IN VARCHAR2,
o_resultset OUT resultset_typ);
END pipeline_example;
CREATE OR REPLACE PACKAGE BODY pipeline_example
IS
FUNCTION base_query (argA IN VARCHAR2, argB IN VARCHAR2)
RETURN resultset_typ
IS
o_resultset resultset_typ;
BEGIN
OPEN o_resultset FOR
SELECT colC, colD, colE
FROM some_table
WHERE colA = ArgA AND colB = argB;
RETURN o_resultset;
END base_query;
FUNCTION processor (
p_source_data IN resultset_typ,
p_limit_size IN PLS_INTEGER DEFAULT c_default_limit)
RETURN table_typ
PIPELINED
PARALLEL_ENABLE(PARTITION p_source_data BY ANY)
IS
aa_source_data table_typ;-- := table_typ ();
BEGIN
LOOP
FETCH p_source_data
BULK COLLECT INTO aa_source_data
LIMIT p_limit_size;
EXIT WHEN aa_source_data.COUNT = 0;
/* Process the batch of (p_limit_size) records... */
FOR i IN 1 .. aa_source_data.COUNT
LOOP
PIPE ROW (aa_source_data (i));
END LOOP;
END LOOP;
CLOSE p_source_data;
RETURN;
END processor;
PROCEDURE with_pipeline (argA IN VARCHAR2,
argB IN VARCHAR2,
o_resultset OUT resultset_typ)
IS
BEGIN
OPEN o_resultset FOR
SELECT /*+ PARALLEL(t, 5) */ colC,
SUM (CASE WHEN colD > colE AND colE != '0' THEN colD / ColE END)de,
SUM (CASE WHEN colE > colD AND colD != '0' THEN colE / ColD END)ed,
SUM (CASE WHEN colD = colE AND colD != '0' THEN '1' END) de_one,
SUM (CASE WHEN colD = '0' OR colE = '0' THEN '0' END) de_zero
FROM TABLE (processor (base_query (argA, argB),100)) t
GROUP BY colC
ORDER BY colC
END with_pipeline;
PROCEDURE no_pipeline (argA IN VARCHAR2,
argB IN VARCHAR2,
o_resultset OUT resultset_typ)
IS
BEGIN
OPEN o_resultset FOR
SELECT colC,
SUM (CASE WHEN colD > colE AND colE != '0' THEN colD / ColE END)de,
SUM (CASE WHEN colE > colD AND colD != '0' THEN colE / ColD END)ed,
SUM (CASE WHEN colD = colE AND colD != '0' THEN 1 END) de_one,
SUM (CASE WHEN colD = '0' OR colE = '0' THEN '0' END) de_zero
FROM (SELECT colC, colD, colE
FROM some_table
WHERE colA = ArgA AND colB = argB)
GROUP BY colC
ORDER BY colC;
END no_pipeline;
END pipeline_example;
ALTER PACKAGE pipeline_example COMPILE;Edited by: Earthlink on Nov 14, 2010 9:47 AM
Edited by: Earthlink on Nov 14, 2010 11:31 AM
Edited by: Earthlink on Nov 14, 2010 11:32 AM
Edited by: Earthlink on Nov 20, 2010 12:04 PM
Edited by: Earthlink on Nov 20, 2010 12:54 PMEarthlink wrote:
Contrary to my understanding, the <font face="courier">with_pipeline</font> procedure runs 6 time slower than the legacy <font face="courier">no_pipeline</font> procedure. Am I missing something? Well, we're missing a lot here.
Like:
- a database version
- how did you test
- what data do you have, how is it distributed, indexed
and so on.
If you want to find out what's going on then use a TRACE with wait events.
All nessecary steps are explained in these threads:
HOW TO: Post a SQL statement tuning request - template posting
http://oracle-randolf.blogspot.com/2009/02/basic-sql-statement-performance.html
Another nice one is RUNSTATS:
http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551378329289980701 -
Performance issue with high CPU and IO
Hi guys,
I am encountering huge user response time on a production system and I don’t know how to solve it.
Doing some extra tests and using the instrumentation that we have in the code we concluded that the DB is the bottleneck.
We generated some AWR reports and noticed the CPU was in top wait events. Also noticed that in a random manner some simple sql take a long time to execute. We activated the sql trace on the system and noticed that for very simple SQLs (unique index access on one table) we have huge exec times. 9s
In the trace file the huge time we had it in fetch area: 9.1s cpu and elapsed 9.2.
And no or very small waits for this specific SQL.
it seems like the bottle neck is on the CPU but at that point there were very few processes running on the DB. Why can we have such a big cpu wait on a simple select? This is a machine with 128 cores. We have quicker responses on machines smaller/busier than this.
We noticed that we had a huge db_cache_size (12G) and after we scale it down we noticed some improvements but not enough. How can I prove that there is a link between high CPU and big cache_size? (there was not wait involved in SQL execution). what can we do in the case we need big DB cache size?
The second issue is that I tried to execute an sql on a big table (FTS on a big table. no join). Again on that smaller machine it runs in 30 seconds and on this machine it runs in 1038 seconds.
Also generated a trace for this SQL on the problematic machine:
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 402.08 1038.31 1842916 6174343 0 1
total 3 402.08 1038.32 1842916 6174343 0 1
db file sequential read 12419 0.21 40.02
i/o slave wait 135475 0.51 613.03
db file scattered read 135475 0.52 675.15
log file switch completion 5 0.06 0.18
latch: In memory undo latch 6 0.00 0.00
latch: object queue header operation 1 0.00 0.00
********************************************************************************The high CPU is present here also but here I have huge wait on db file scattered read.
Looking at the session with the select the AWG_wait for db scattered read was 0.5. on the other machine it is like 0.07.
I though this is an IO issue. I did some IO tests at SO level and it seems like the read and writes operation are very fast…much faster than the machine that has the awg_wait smaller. Why the difference in waits?
One difference between these two DBs is that the problem one has the db block size = 16k and the other one has 8k.
I received some reports done at OS level on CPU and IO usage on the problematic machine (in normal operations). It seems like the CPU is very used and the IO stays very low.
On the other machine, the smaller and the faster one, it is other way around.
What is the problem here? How can I test further? Can I link the high CPU to low/slow IO?
we have 10G on sun os with ASM.
Thanks in advance.Yes, there are many things you can and should do to isolate this. But first check MOS Poor Performance With Oracle9i and 10g Releases When Using Dynamic Intimate Shared Memory (DISM) [ID 1018855.1] isn't messing you up to start.
Also, be sure and post exact patch levels for both Oracle and OS.
Be sure and check all your I/O settings and see what MOS has to say about those.
Are you using ASSM? See Long running update
Since it got a little better with shrinking the SGA size, that might indicate (wild speculation here, something like) one of the problems is simply too much thrashing within the SGA, as oracle decides "small" objects being full scanned in memory is faster than range scans (or whatever) from disk, overloading the cpu, not allowing the cpu to ask for other full scans from I/O. Possibly made worse by row level locking, or some other app issue that just does too much cpu.
You probably have more than one thing wrong. High fetch count might mean you need to adjust the array size on the clients.
Now that that is all out of the way, if you still haven't found the problem, go through http://oracle-randolf.blogspot.com/2009/02/basic-sql-statement-performance.html
Edit: Oh, see Solaris 10 memory management conflicts with Automatic PGA Memory Management [ID 460424.1] too.
Edited by: jgarry on Nov 15, 2011 1:45 PM -
HOW TO: Post a SQL statement tuning request - template posting
This post is not a question, but similar to Rob van Wijk's "When your query takes too long ..." post should help to improve the quality of the requests for SQL statement tuning here on OTN.
On the OTN forum very often tuning requests about single SQL statements are posted, but the information provided is rather limited, and therefore it's not that simple to provide a meaningful advice. Instead of writing the same requests for additional information over and over again I thought I put together a post that describes how a "useful" post for such a request should look like and what information it should cover.
I've also prepared very detailed step-by-step instructions how to obtain that information on my blog, which can be used to easily gather the required information. It also covers again the details how to post the information properly here, in particular how to use the \ tag to preserve formatting and get a fixed font output:
http://oracle-randolf.blogspot.com/2009/02/basic-sql-statement-performance.html
So again: This post here describes how a "useful" post should look like and what information it ideally covers. The blog post explains in detail how to obtain that information.
In the future, rather than requesting the same additional information and explaining how to obtain it, I'll simply refer to this HOW TO post and the corresponding blog post which describes in detail how to get that information.
*Very important:*
Use the \ tag to enclose any output that should have its formatting preserved as shown below.
So if you want to use fixed font formatting that preserves the spaces etc., do the following:
\ This preserves formatting
\And it will look like this:
This preserves formatting
. . .Your post should cover the following information:
1. The SQL and a short description of its purpose
2. The version of your database with 4-digits (e.g. 10.2.0.4)
3. Optimizer related parameters
4. The TIMING and AUTOTRACE output
5. The EXPLAIN PLAN output
6. The TKPROF output snippet that corresponds to your statement
7. If you're on 10g or later, the DBMS_XPLAN.DISPLAY_CURSOR output
The above mentioned blog post describes in detail how to obtain that information.
Your post should have a meaningful subject, e.g. "SQL statement tuning request", and the message body should look similar to the following:
*-- Start of template body --*
The following SQL statement has been identified to perform poorly. It currently takes up to 10 seconds to execute, but it's supposed to take a second at most.
This is the statement:
select
from
t_demo
where
type = 'VIEW'
order by
id;It should return data from a table in a specific order.
The version of the database is 11.1.0.7.
These are the parameters relevant to the optimizer:
SQL>
SQL> show parameter optimizer
NAME TYPE VALUE
optimizer_capture_sql_plan_baselines boolean FALSE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 11.1.0.7
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
optimizer_use_invisible_indexes boolean FALSE
optimizer_use_pending_statistics boolean FALSE
optimizer_use_sql_plan_baselines boolean TRUE
SQL>
SQL> show parameter db_file_multi
NAME TYPE VALUE
db_file_multiblock_read_count integer 8
SQL>
SQL> show parameter db_block_size
NAME TYPE VALUE
db_block_size integer 8192
SQL>
SQL> show parameter cursor_sharing
NAME TYPE VALUE
cursor_sharing string EXACT
SQL>
SQL> column sname format a20
SQL> column pname format a20
SQL> column pval2 format a20
SQL>
SQL> select
2 sname
3 , pname
4 , pval1
5 , pval2
6 from
7 sys.aux_stats$;
SNAME PNAME PVAL1 PVAL2
SYSSTATS_INFO STATUS COMPLETED
SYSSTATS_INFO DSTART 01-30-2009 16:25
SYSSTATS_INFO DSTOP 01-30-2009 16:25
SYSSTATS_INFO FLAGS 0
SYSSTATS_MAIN CPUSPEEDNW 494,397
SYSSTATS_MAIN IOSEEKTIM 10
SYSSTATS_MAIN IOTFRSPEED 4096
SYSSTATS_MAIN SREADTIM
SYSSTATS_MAIN MREADTIM
SYSSTATS_MAIN CPUSPEED
SYSSTATS_MAIN MBRC
SYSSTATS_MAIN MAXTHR
SYSSTATS_MAIN SLAVETHR
13 rows selected.Here is the output of EXPLAIN PLAN:
SQL> explain plan for
2 -- put your statement here
3 select
4 *
5 from
6 t_demo
7 where
8 type = 'VIEW'
9 order by
10 id;
Explained.
Elapsed: 00:00:00.01
SQL>
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 1390505571
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 60 | 0 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T_DEMO | 1 | 60 | 0 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_DEMO | 1 | | 0 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("TYPE"='VIEW')
14 rows selected.Here is the output of SQL*Plus AUTOTRACE including the TIMING information:
SQL> rem Set the ARRAYSIZE according to your application
SQL> set autotrace traceonly arraysize 100
SQL> select
2 *
3 from
4 t_demo
5 where
6 type = 'VIEW'
7 order by
8 id;
149938 rows selected.
Elapsed: 00:00:02.21
Execution Plan
Plan hash value: 1390505571
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 60 | 0 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T_DEMO | 1 | 60 | 0 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_DEMO | 1 | | 0 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("TYPE"='VIEW')
Statistics
0 recursive calls
0 db block gets
149101 consistent gets
800 physical reads
196 redo size
1077830 bytes sent via SQL*Net to client
16905 bytes received via SQL*Net from client
1501 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
149938 rows processed
SQL>
SQL> disconnect
Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing optionsThe TKPROF output for this statement looks like the following:
TKPROF: Release 11.1.0.7.0 - Production on Mo Feb 23 10:23:08 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Trace file: orcl11_ora_3376_mytrace1.trc
Sort options: default
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
select
from
t_demo
where
type = 'VIEW'
order by
id
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1501 0.53 1.36 800 149101 0 149938
total 1503 0.53 1.36 800 149101 0 149938
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 88
Rows Row Source Operation
149938 TABLE ACCESS BY INDEX ROWID T_DEMO (cr=149101 pr=800 pw=0 time=60042 us cost=0 size=60 card=1)
149938 INDEX RANGE SCAN IDX_DEMO (cr=1881 pr=1 pw=0 time=0 us cost=0 size=0 card=1)(object id 74895)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 1501 0.00 0.00
db file sequential read 800 0.05 0.80
SQL*Net message from client 1501 0.00 0.69
********************************************************************************The DBMS_XPLAN.DISPLAY_CURSOR output:
SQL> -- put your statement here
SQL> -- use the GATHER_PLAN_STATISTICS hint
SQL> -- if you're not using STATISTICS_LEVEL = ALL
SQL> select /*+ gather_plan_statistics */
2 *
3 from
4 t_demo
5 where
6 type = 'VIEW'
7 order by
8 id;
149938 rows selected.
Elapsed: 00:00:02.21
SQL>
SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
SQL_ID d4k5acu783vu8, child number 0
select /*+ gather_plan_statistics */ * from t_demo
where type = 'VIEW' order by id
Plan hash value: 1390505571
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads |
| 0 | SELECT STATEMENT | | 1 | | 149K|00:00:00.02 | 149K| 1183 |
| 1 | TABLE ACCESS BY INDEX ROWID| T_DEMO | 1 | 1 | 149K|00:00:00.02 | 149K| 1183 |
|* 2 | INDEX RANGE SCAN | IDX_DEMO | 1 | 1 | 149K|00:00:00.02 | 1880 | 383 |
Predicate Information (identified by operation id):
2 - access("TYPE"='VIEW')
20 rows selected.I'm looking forward for suggestions how to improve the performance of this statement.
*-- End of template body --*
I'm sure that if you follow these instructions and obtain the information described, post them using a proper formatting (don't forget about the \ tag) you'll receive meaningful advice very soon.
So, just to make sure you didn't miss this point:Use proper formatting!
If you think I missed something important in this sample post let me know so that I can improve it.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/Alex Nuijten wrote:
...you missed the proper formatting of the Autotrace section ;-)Alex,
can't reproduce, does it still look unformatted? Or are you simply kidding? :-)
Randolf
PS: Just noticed that it actually sometimes doesn't show the proper formatting although the code tags are there. Changing to the \ tag helped in this case, but it seems to be odd.
Edited by: Randolf Geist on Feb 23, 2009 11:28 AM
Odd behaviour of forum software -
Just a helpful SAP note for slow SQL statements
Hi Guys,
Just wanted to share this SAP note with you. I am sure many of you might have gone through it.
[SAP Note 155413 - Analysis of slow SQL statements|https://websmp130.sap-ag.de/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/sapnotes/index2.htm?numm=155413]
Cheers,
Abu>
ZAFCO ABAP wrote:
> Hi Guys,
>
> Just wanted to share this SAP note with you. I am sure many of you might have gone through it.
>
> [SAP Note 155413 - Analysis of slow SQL statements|https://websmp130.sap-ag.de/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/sapnotes/index2.htm?numm=155413]
>
> Cheers,
> Abu
Hi,
I would bet not as many as you might think - many questions here suffering form not GOING through
the analysis before they post it here.
Meantime I think questions to SQL statement performance here will only be answered when the execution plan on the statement is posted with it.
bye
yk -
Performance issue with pl/sql code
Hi Oracle Gurus,
I am in need of your recommendations for a performance issue that I am facing in production envrionment. There is a pl/sql procedure which executes with different elapsed time at different executions. Elapsed Times are 30minutes , 40 minutes, 65 minutes , 3 minutes ,3 seconds.
Expected elapsed time is maximum of 3 minutes. ( But some times it took 3 seconds too...! )
Output on all different executions are same that is deletion and insertion of 12K records into a table.
Here is the auto trace details of two different scenarios.
Slow execution - 33.65 minutes
Stat Name Statement Per Execution % Snap
Elapsed Time (ms) 1,712,343 1,712,342.6 41.4
CPU Time (ms) 1,679,689 1,679,688.6 44.7
Executions 1 N/A N/A
Buffer Gets ########## 167,257,973.0 86.9
Disk Reads 1,284 1,284.0 0.4
Parse Calls 1 1.0 0.0
User I/O Wait Time (ms) 4,264 N/A N/A
Cluster Wait Time (ms) 3,468 N/A N/A
Application Wait Time (ms) 0 N/A N/A
Concurrency Wait Time (ms) 6 N/A N/A
Invalidations 0 N/A N/A
Version Count 4 N/A N/A
Sharable Mem(KB) 85 N/A N/A
-------------------------------------------------------------Fast Exection : 5 seconds
Stat Name Statement Per Execution % Snap
Elapsed Time (ms) 41,550 41,550.3 0.7
CPU Time (ms) 40,776 40,776.3 1.0
Executions 1 N/A N/A
Buffer Gets 2,995,677 2,995,677.0 4.2
Disk Reads 22 22.0 0.0
Parse Calls 1 1.0 0.0
User I/O Wait Time (ms) 162 N/A N/A
Cluster Wait Time (ms) 621 N/A N/A
Application Wait Time (ms) 0 N/A N/A
Concurrency Wait Time (ms) 55 N/A N/A
Invalidations 0 N/A N/A
Version Count 4 N/A N/A
Sharable Mem(KB) 85 N/A N/A
-------------------------------------------------------------For security reasons, I cannot share the actual code. Its a report generating code that deletes and load the data into table using insert into select statement.
Delete from table ;
cursor X to get the master data ( 98 records )
For each X loop
insert into tableA select * from tables where a= X.a and b= X.b and c=X.c ..... ;
-- 12 K records inserted on average
insert into tableB select * from tables where a= X.a and b= X.b and c=X.c ..... ;
-- 12 K records inserted on average
end loop ;1. The select query is complex with bind variables ( explain plan varies for each values )
2. I have checked the tablespace of the tables involved, it is 82% used. DBA confirmed that it is not the reason.
3. Disk reads are high during long execution.
4. At long running times, I can see a db sequential read wait event on a index object. This index is on the table where data is inserted.
All I need to find is why this code is taking 3 seconds and 60 minutes on the same day and on the consecutive executions ?
Is there any other approach to find the root cause of this behaviour and to fix it ? Kindly adivse.
Thanks in advance your help.
Regards,
Hari
Edited by: BluShadow on 26-Sep-2012 08:24
edited to add {noformat}{noformat} tags. You've been a member long enough to know to do this yourself... so please do so in future. ({message:id=9360002})Hariharan ST wrote:
Hi Oracle Gurus,
I am in need of your recommendations for a performance issue that I am facing in production envrionment. There is a pl/sql procedure which executes with different elapsed time at different executions. Please reedit your post and add some code tags around the trace information. This would improve readability greatly and will help us to help you
example
{<b></b>code}
select * from dual;{<b></b>code}
Based upon your description I can imagine two things.
a) The execution plan for the select query does change frequently.
A typical reason can be not up to date statistics.
b) Some locking / wait conflict. For example upon a UK index.
Are there any other operations going on while it is slow? If anybody inserts a value, then your session will wait, if the same (PK/UK) value also is to be inserted.
Those wait events can be recognized using standard tools like oracle sql developer or enterprise manager while the query is slow.
Also go through the links that are in the FAQ. They tell you how to get better information for makeing a tuning request.
SQL and PL/SQL FAQ
Edited by: Sven W. on Sep 25, 2012 6:41 PM
Maybe you are looking for
-
Safari keeps crashing and breaking my heart
Hello smart computer fixers! This problem just started this afternoon. I had Safari open and it quit unexpectedly, which happens occasionally, so I started it up again, only to have it quit unexpectedly. It will stay on a website for a few seconds be
-
Use smart mailbox to find email with specific text in attached pdf
Does anyone known if a smart mailbox can be created to find emails with specific text within a pdf attached document. I know that spotlight can do this and it works fine but it would suite me better to be able to do this in mail.
-
Switched from openbox to Awesome, now i get no sound! [SOLVED]
Hi all, I have just switched from openbox to awesome and within awesome i get no sound, but if i swith back to openbox i get sound. Within awesome i get this output whenever i run any command that requires sound! ALSA lib confmisc.c:768:(parse_card)
-
In what format oblixpersonpwdpolicy's attribute oblockouttime is stored
I am using COREid 7.0.4. I have configured oblixpersonpwdpolicy for locking user account after n number of wrong attempts. The attribute 'oblockouttime' store the date time when the user is locked. I checked the LDAP and found one of the value for 'o
-
Identify selection of sub-total line in ALV grid
Hi folks, Is there a way to identify in the report if the user has selected any sub-total line in an ALV grid? Both for REUSE_ALV_GRID_DISPLAY and CL_GUI_ALV_GRID. Thanks Sagar