Reduce the Number of SQL Statements
2011-08-08 16:53
239 查看
Shareable SQL uses bind variables rather than literal values. If an application makes use of literal (unshared) SQL then this can severely limit scalability and throughput. The cost of parsing a new SQL statement is expensive both in terms of CPU and the number of times the library cache and shared pool latches may need to be acquired and released. Even parsing a simple SQL statement may need to acquire a library cache latch twenty or thirty times.
By looking at the V$SQLAREA view it is possible to see which literal statements are good candidates for converting to use bind variables. The following query shows SQL in the SGA where there are a large number of similar statements:
SELECT substr(sql_text,1,50) "SQL",
count(*),
sum(executions) "TotExecs"
FROM v$sqlarea
WHERE executions < 5
GROUP BY substr(sql_text,1,50)
HAVING count(*) > 30
ORDER BY 2
This query finds statements whose first 50 characters are the same and which have only been executed a few times each and have at least 30 different copies of this SQL in the shared pool. The query may need to be modified if the literals are in the first 50 characters.
There are numerous parameters in the INIT.ORA that can directly impact the efficiency of shared pool usage. For a full accounting of these, refer to MetaLink Note: 62143.1.本文出自 “Ask Maclean Liu Oracle” 博客,请务必保留此出处http://maclean.blog.51cto.com/2923249/1277878
By looking at the V$SQLAREA view it is possible to see which literal statements are good candidates for converting to use bind variables. The following query shows SQL in the SGA where there are a large number of similar statements:
SELECT substr(sql_text,1,50) "SQL",
count(*),
sum(executions) "TotExecs"
FROM v$sqlarea
WHERE executions < 5
GROUP BY substr(sql_text,1,50)
HAVING count(*) > 30
ORDER BY 2
This query finds statements whose first 50 characters are the same and which have only been executed a few times each and have at least 30 different copies of this SQL in the shared pool. The query may need to be modified if the literals are in the first 50 characters.
There are numerous parameters in the INIT.ORA that can directly impact the efficiency of shared pool usage. For a full accounting of these, refer to MetaLink Note: 62143.1.本文出自 “Ask Maclean Liu Oracle” 博客,请务必保留此出处http://maclean.blog.51cto.com/2923249/1277878
相关文章推荐
- Reduce the Number of SQL Statements
- sql语句遇到错误: The used SELECT statements have a different number of columns :
- sql异常-The used SELECT statements have a different number of columns
- mysql The used SELECT statements have a different number of columns
- 91.View the Exhibit and examine the structure of the PROMOTIONS table. Which two SQL statements woul
- UNION关键字报错:ERROR 1222 (21000): The used SELECT statements have a different number of columns
- The used SELECT statements have a different number of columns
- Questions[SQL]:Calculate the Number of Days in a Month
- Change the value of "Maximum number of concurrent connections" about SQL Server 2012
- Microsoft SQL Server 2008 R2 XML处理 One solution is to increase the number of characters retrieved from the server for XML data.
- Controlling the number of Partitions in Spark for shuffle transformations (Ex. reduceByKey)
- ERROR 1222 (21000): The used SELECT statements have a different number of columns
- ERROR 1222 (21000): The used SELECT statements have a different number of columns
- ERROR 1222 (21000): The used SELECT statements have a different number of columns
- [Err] 1222 - The used SELECT statements have a different number of columns
- 异常:java.sql.SQLException: The total number of locks exceeds the lock table size
- The used SELECT statements have a different number of columns 错误解决
- The Maximum Number of Bytes Per Row in SQL Server 2000 -- 8060.
- The Power of SQL CASE Statements
- change the number of recent workspaces