carfield.com.hk Note of SQL performance tuning.txt 2023-02-01T02:37:46Z 2023-02-01T02:37:46Z <br/>Note of this book - <a href="http://www.ocelot.ca/tuning.htm">http://www.ocelot.ca/tuning.htm</a> <br/><br/>1) Order of "and" and "or" is matter, if no cost-base optimizer<br/><br/>where column1 = 'a' and column2 = 'b' -> where column2 = 'b' and column1 = 'a' if column2 'b' is less likely<br/><br/>2) <> is more expensive than =<br/><br/>3) Can force to use index if SELECT * FROM table WHERE indexed_column > 0<br/><br/>4) UPPER(column) might lose information, use LOWER is better<br/><br/>5) WHERE column = 'WORD' or column = 'word' is always faster than WHERE LOWER(column) = 'word' , even faster version is test if database if case-insensitive: WHERE column = 'WORD' or ('WORD' <> 'word' AND column = 'word')<br/><br/>6) 32bit integer is the fastest datatype for 32bit OS<br/><br/>7) column in (?, ?) is faster than column =? or column = ? for some database, and don't slow in any database<br/><br/>8) For aggregate functions, prevent using having, try to use fewer columns in group by and use subquery if possible<br/><br/>9) In fact, count(1) is not faster than count(*)<br/><br/>10) CAST before aggregate function: SELECT CAST(SUM(column) AS INT) -> SELECT SUM(CAST(column as INT))<br/><br/>11) Use constant as much as possible, e.g.: select * from t1, t2 where t1.c1 = t2.c1 and t1.c1 = 1 -> select * from t1, t2 where t1.c1=1 andn t2.c1=1<br/><br/>12) Information of Join vs Subqueries<br/><br/>13) Information of optimum column type (VARCHAR, TIMESTAMP, WORD size INT and CHAR(1) usually better), shift effect for page<br/><br/>14) prevent NULL for porting issue<br/><br/>15) Low level table physical information<br/><br/>Some related links - <a href="http://www.techartifact.com/blogs/2009/12/sql-optimization-tipsquestions.html">http://www.techartifact.com[..]9/12/sql-optimization-tipsquestions.html</a> <br/><br/>16) Prevent database level transaction, prevent joining, prevent locking ( like auto increment key ), pretty good suggestion - <a href="http://www.aviransplace.com/2015/08/12/mysql-is-a-great-nosql/">http://www.aviransplace.com/2015/08/12/mysql-is-a-great-nosql/</a> <br/><br/>17) Reduce dataset for aggregation - <a href="https://www.periscopedata.com/blog/use-subqueries-to-count-distinct-50x-faster">https://www.periscopedata.com[..]-subqueries-to-count-distinct-50x-faster</a> <br/><br/>Few good tips, like avoid cursors - <a href="http://www.javaworld.com/article/3209906/application-development/21-rules-for-faster-sql-queries.html">http://www.javaworld.com[..]ent/21-rules-for-faster-sql-queries.html</a> <br/><br/>7 Tips for Query Optimization in SQL Servers - <a href="https://learningdaily.dev/7-tips-for-query-optimization-in-sql-servers-fb3653c910f1">https://learningdaily.dev[..]optimization-in-sql-servers-fb3653c910f1</a> <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2023-02-01T02:37:46Z index.txt 2021-06-24T14:57:56Z 2021-06-24T14:57:56Z <br/>Case study about how to find out suitable index - <a href="http://samsaffron.com/archive/2011/05/02/A+day+in+the+life+of+a+slow+page+at+Stack+Overflow#">http://samsaffron.com[..]e+life+of+a+slow+page+at+Stack+Overflow#</a> <br/><br/>A simple example of how to use EXPLAIN to find out the bottleneck of the query and add suitable index to suitable column - <a href="http://hackmysql.com/case4">http://hackmysql.com/case4</a> <br/><br/>Bitmap Index vs. B-tree Index: Which and When? - <a href="http://www.oracle.com/technology/pub/articles/sharma_indexes.html">http://www.oracle.com/technology/pub/articles/sharma_indexes.html</a> <a href="http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=/rzajq/perf21c.htm">http://publib.boulder.ibm.com[..]/v5r3/index.jsp?topic=/rzajq/perf21c.htm</a> <br/><br/>script to check if index is missing at foreign key<br/><pre><br/>select table_name, constraint_name,<br/> cname1 || nvl2(cname2,','||cname2,null) ||<br/> nvl2(cname3,','||cname3,null) || nvl2(cname4,','||cname4,null) ||<br/> nvl2(cname5,','||cname5,null) || nvl2(cname6,','||cname6,null) ||<br/> nvl2(cname7,','||cname7,null) || nvl2(cname8,','||cname8,null)<br/> columns<br/> from ( select b.table_name,<br/> b.constraint_name,<br/> max(decode( position, 1, column_name, null )) cname1,<br/> max(decode( position, 2, column_name, null )) cname2,<br/> max(decode( position, 3, column_name, null )) cname3,<br/> max(decode( position, 4, column_name, null )) cname4,<br/> max(decode( position, 5, column_name, null )) cname5,<br/> max(decode( position, 6, column_name, null )) cname6,<br/> max(decode( position, 7, column_name, null )) cname7,<br/> max(decode( position, 8, column_name, null )) cname8,<br/> count(*) col_cnt<br/> from (select substr(table_name,1,30) table_name,<br/> substr(constraint_name,1,30) constraint_name,<br/> substr(column_name,1,30) column_name,<br/> position<br/> from sys.user_cons_columns ) a,<br/> sys.user_constraints b<br/> where a.constraint_name = b.constraint_name<br/> and b.constraint_type = 'R'<br/> group by b.table_name, b.constraint_name<br/> ) cons<br/> where col_cnt > ALL<br/> ( select count(*)<br/> from sys.user_ind_columns i<br/> where i.table_name = cons.table_name<br/> and i.column_name in (cname1, cname2, cname3, cname4,<br/> cname5, cname6, cname7, cname8 )<br/> and i.column_position <= cons.col_cnt<br/> group by i.index_name<br/> ) <br/></pre><br/><a href="http://chriswongdevblog.blogspot.com.au/2013/01/dont-forget-to-index-your-oracle.html">http://chriswongdevblog.blogspot.com.au[..]01/dont-forget-to-index-your-oracle.html</a> <br/><br/>Explain how postgres indexes work, look like combine index is not that useful - <a href="http://dublintech.blogspot.com.au/2015/07/postgres-indexes.html">http://dublintech.blogspot.com.au/2015/07/postgres-indexes.html</a> <br/><br/>SQL Server JDBC – Set sendStringParametersAsUnicode to false - <a href="https://vladmihalcea.com/sql-server-jdbc-sendstringparametersasunicode/">https://vladmihalcea.com[..]rver-jdbc-sendstringparametersasunicode/</a> <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2021-06-24T14:57:56Z numa.txt 2017-11-03T01:41:42Z 2017-11-03T01:41:42Z <br/><a href="https://technet.microsoft.com/en-us/library/ms345403(v=sql.105).aspx">https://technet.microsoft.com[..]m/en-us/library/ms345403(v=sql.105).aspx</a> <br/><br/><a href="https://code.kx.com/q/cookbook/linux-production/">https://code.kx.com/q/cookbook/linux-production/</a> <br/><br/><a href="http://jcole.us/blog/archives/2010/09/28/mysql-swap-insanity-and-the-numa-architecture/">http://jcole.us[..]swap-insanity-and-the-numa-architecture/</a> <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2017-11-03T01:41:42Z architecture.txt 2017-09-22T07:29:28Z 2017-09-22T07:29:28Z <br/>IT Hare: Ultimate DB Heresy: Single Modifying DB Connection. Part I. Performanc - <a href="http://highscalability.com/blog/2016/11/22/it-hare-ultimate-db-heresy-single-modifying-db-connection-pa.html">http://highscalability.com[..]y-single-modifying-db-connection-pa.html</a> <br/><br/>How yandex.metrica improve DB reading - <a href="http://highscalability.com/blog/2017/9/18/evolution-of-data-structures-in-yandexmetrica.html">http://highscalability.com[..]of-data-structures-in-yandexmetrica.html</a> <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2017-09-22T07:29:28Z JDBC performance tips.txt 2016-02-01T04:26:28Z 2016-02-01T04:26:28Z <br/>Some tips, like use of addBatch()<br/><br/><a href="http://rgarg.blogspot.com/2005/10/jdbc-performance-pointers.html">http://rgarg.blogspot.com/2005/10/jdbc-performance-pointers.html</a> <br/><a href="http://www.theserverside.com/articles/content/JDBCPerformance_PartIII/article.html">http://www.theserverside.com[..]ent/JDBCPerformance_PartIII/article.html</a> <br/><br/>Nice discussion about preparestatement caching<br/><br/><a href="http://www.theserverside.com/news/thread.tss?thread_id=27528">http://www.theserverside.com/news/thread.tss?thread_id=27528</a> <a href="http://www.ibm.com/developerworks/java/library/j-jdbcnew/">http://www.ibm.com/developerworks/java/library/j-jdbcnew/</a> <br/><br/><a href="http://blog.jooq.org/2014/05/26/yet-another-10-common-mistakes-java-developer-make-when-writing-sql-you-wont-believe-the-last-one/">http://blog.jooq.org[..]iting-sql-you-wont-believe-the-last-one/</a> <br/><br/>Statement.getWarnings() is expensive - <a href="https://plumbr.eu/blog/io/how-we-accidentally-doubled-our-jdbc-traffic-with-hibernate">https://plumbr.eu[..]-doubled-our-jdbc-traffic-with-hibernate</a> <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2016-02-01T04:26:28Z embedded.txt 2013-01-06T11:22:03Z 2013-01-06T11:22:03Z <br/>Compare the performance of LevelDB, BDB and BangDB, it sound like BangDB is best... but this article from BangDB - <a href="http://highscalability.com/blog/2012/11/29/performance-data-for-leveldb-berkley-db-and-bangdb-for-rando.html">http://highscalability.com[..]ldb-berkley-db-and-bangdb-for-rando.html</a> <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2013-01-06T11:22:03Z parameter sniffing.txt 2011-06-30T16:34:29Z 2011-06-30T16:34:29Z <br/>When the query plan is compiled on first run of the procedure after a SQL Server restart, the query is optimised for those initial variables in that initial call.<br/> <br/>There’s ways to write the procedure to have a more representative query plan chosen on initial compile each time:<br/> <br/><a href="http://blogs.msdn.com/b/queryoptteam/archive/2006/03/31/565991.aspx">http://blogs.msdn.com[..]ryoptteam/archive/2006/03/31/565991.aspx</a> <br/> <br/>This is what is known as parameter sniffing.<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2011-06-30T16:34:29Z count.txt 2011-04-29T01:34:07Z 2011-04-29T01:34:07Z <br/>Tip of having faster 'select count(*) from table' of sql server, probably can use this as reference to check similar feature on other DB, if that hurt something - <a href="http://beyondrelational.com/blogs/nakul/archive/2011/04/04/measuring-the-number-of-rows-in-a-table-are-there-any-alternatives-to-count.aspx">http://beyondrelational.com[..]are-there-any-alternatives-to-count.aspx</a> <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2011-04-29T01:34:07Z sharding.txt 2009-03-27T15:02:05Z 2009-03-27T15:02:05Z <br/>An idea of database sharding, basically replicate a unified version for operation required global access - <a href="http://itsfrosty.wordpress.com/2009/03/20/database-sharding-basics/">http://itsfrosty.wordpress.com[..]com/2009/03/20/database-sharding-basics/</a> <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2009-03-27T15:02:05Z MaterializedView.txt 2009-03-27T03:49:44Z 2009-03-27T03:49:44Z <br/>Oracle can help us to denormalize tables according to query via materialized view, should help performance a lot, probably there is similar feature in other DBMS - <a href="http://www.oracle.com/technology/products/oracle9i/daily/jul05.html">http://www.oracle.com[..]ology/products/oracle9i/daily/jul05.html</a> <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2009-03-27T03:49:44Z