<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1572547582182708302</id><updated>2011-11-28T05:17:15.372+05:00</updated><category term='function calling'/><category term='indexes'/><category term='db design'/><category term='join table'/><category term='locks'/><category term='junction table'/><category term='MySQL'/><category term='c/c++'/><category term='bridge table'/><category term='database design'/><category term='entity relationship'/><category term='many-to-many relationship'/><category term='programming'/><category term='perl'/><category term='coding'/><category term='link table'/><category term='indexing'/><category term='mapping table'/><category term='referential integrity'/><category term='locking'/><category term='database'/><category term='db'/><title type='text'>J's Blog</title><subtitle type='html'>Its not J for Java, its J for Jawaid!</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://mjawaids.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://mjawaids.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jawaid</name><uri>http://www.blogger.com/profile/05875874113914026501</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1572547582182708302.post-521726772728163872</id><published>2009-08-07T10:30:00.002+06:00</published><updated>2009-08-07T10:38:16.512+06:00</updated><title type='text'>Useful Vim option for techies</title><content type='html'>Vim is very useful tool for editing files, especially for techies to edit configuration and code files. There are some useful options for them in vim. You can set them in the vim configuration file &lt;span style="font-family: courier new;"&gt;vimrc&lt;/span&gt; usually found in &lt;span style="font-family: courier new;"&gt;/etc&lt;/span&gt;. Here are some of those options:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;syntax on            " Turn on syntax highlighting&lt;br /&gt;set incsearch        " Used for incremental searching&lt;br /&gt;set hlsearch         " Turns on highlighting for matched search patterns&lt;br /&gt;set tabstop=4        " Sets the tab size to 4&lt;br /&gt;set shiftwidth=4     " Sets spaces used for (auto)indent&lt;br /&gt;set shiftround       " Indent to nearest tabstop&lt;br /&gt;set autoindent       " Carries over previous indent to the next line&lt;br /&gt;&lt;/pre&gt;Note: Double quotes (") are used for comments.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1572547582182708302-521726772728163872?l=mjawaids.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mjawaids.blogspot.com/feeds/521726772728163872/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1572547582182708302&amp;postID=521726772728163872' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/521726772728163872'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/521726772728163872'/><link rel='alternate' type='text/html' href='http://mjawaids.blogspot.com/2009/08/useful-vim-option-for-techies.html' title='Useful Vim option for techies'/><author><name>Jawaid</name><uri>http://www.blogger.com/profile/05875874113914026501</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1572547582182708302.post-1601188739942958368</id><published>2009-08-07T10:29:00.000+06:00</published><updated>2009-08-07T10:30:09.182+06:00</updated><title type='text'>How to install MQSeries Perl Extension for IBM WebSphere MQ</title><content type='html'>&lt;div class="snap_preview"&gt;&lt;p&gt;I was having some issues installing &lt;a class="wp-caption" title="MQSeries Perl Extension" href="http://search.cpan.org/dist/MQSeries/" target="_blank"&gt;MQSeries Perl Extension 1.29&lt;/a&gt; for &lt;a class="wp-caption" title="IBM WebSphere MQ" href="http://www.ibm.com/webspheremq" target="_blank"&gt;IBM WebSphere MQ (WMQ)&lt;/a&gt;. What actually I did was downloaded the MQSeries module from the CPAN, extracted it and ran the &lt;em&gt;perl Makefile.PL&lt;/em&gt;. But it gave me the following error:&lt;/p&gt; &lt;p&gt;&lt;em&gt;&gt; perl Makefile.PL&lt;br /&gt;Checking if your kit is complete…&lt;br /&gt;Looks good&lt;br /&gt;ERROR from evaluation of /root/MQSeries-1.29/MQClient/Makefile.PL: No such directory ‘/opt/mqm’&lt;br /&gt;Compilation failed in require at ./Makefile.PL line 14.&lt;br /&gt;# Looks like your test died before it could output anything.&lt;/em&gt;&lt;/p&gt; &lt;p&gt;This seem as it needs &lt;em&gt;/opt/mqm&lt;/em&gt; directory to install to and its not creating it by itself. But this was foolish assumption, as most applications create the required directories itself when installing, but still there wasn’t any clear error message. Then somehow I came to know about the client and I installed the MQSeriesClient. Installing MQSeriesClient requires MQSeriesRuntime as well. This created two directories:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;em&gt; /opt/mqm &lt;/em&gt;and&lt;/li&gt;&lt;li&gt;&lt;em&gt; /var/mqm&lt;/em&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;So, that means Perl Extension was unable to find the client, but instead it was complaining about the directory. Well I moved forward and tried again installing MQSeries Perl Extension. But what? again error?&lt;/p&gt; &lt;p&gt;&lt;em&gt;&gt; perl Makefile.PL&lt;br /&gt;Checking if your kit is complete…&lt;br /&gt;Looks good&lt;br /&gt;ERROR from evaluation of /home/jawaid/MQSeries-1.29/MQClient/Makefile.PL: Missing inc or include directory in /opt/mqm&lt;br /&gt;Compilation failed in require at ./Makefile.PL line 14.&lt;br /&gt;# Looks like your test died before it could output anything.&lt;/em&gt;&lt;/p&gt; &lt;p&gt;dahhh!! Now its complaining about another directory &lt;em&gt;inc&lt;/em&gt; or &lt;em&gt;include&lt;/em&gt; in &lt;em&gt;/opt/mqm&lt;/em&gt;. That means it requires something else as well. The name of the directory i.e &lt;em&gt;include&lt;/em&gt;, sparked in my mind that it might requires some kind of SDK or something. Then I checked the RPMs came with WMQ. I found MQSeriesSDK. hmmm so I thought lets try installing this RPM and try my luck again with installing Perl Extension. So I installed MQSeriesSDK and then MQSeries Perl Extension. woala!! this time it generated the make file without any errors &lt;img src="http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /&gt; &lt;/p&gt; &lt;p&gt;&lt;em&gt;&gt; perl Makefile.PL&lt;br /&gt;Checking if your kit is complete…&lt;br /&gt;Looks good&lt;br /&gt;Writing Makefile for MQClient::MQSeries&lt;br /&gt;Writing Makefile for MQSeries::Message::DeadLetter&lt;br /&gt;Writing Makefile for MQSeries::Message::PCF&lt;br /&gt;Warning: Guessing NAME [MQSeries-OAM] from current directory name.&lt;br /&gt;No libmqm server library found, MQServer disabled&lt;br /&gt;Support for MQServer is disabled on this platform.&lt;br /&gt;Warning: Guessing NAME [MQServer] from current directory name.&lt;br /&gt;Writing Makefile for MQSeries&lt;/em&gt;&lt;/p&gt; &lt;p&gt;But hold your breath for more. You can expect anything now after happening all this. Anyway, I ran &lt;em&gt;make&lt;/em&gt; successfully then ran &lt;em&gt;make test&lt;/em&gt;… what?? it failed??  :’(&lt;/p&gt; &lt;p&gt;aaahhh!! now what?? never mind!! I just ran &lt;em&gt;make install&lt;/em&gt;… guess what? no, you are wrong &lt;img src="http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /&gt;  no errors this time, it got installed, even after failing the make test &lt;img src="http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /&gt; &lt;/p&gt; &lt;p&gt;To verify i tried to run the example perl script in &lt;em&gt;examples &lt;/em&gt;directory of MQSeries Perl Extension to put message in the queue, and i got an error from the MQSeries library that it didn’t find the queue, obviously there were no queues at the moment, that means Perl module is installed correctly…whew!!&lt;/p&gt; &lt;p&gt;That means installing the run time and client are not enough. You need to install the WMQ SDK as well to install the MQSeries Perl Extension.&lt;/p&gt; &lt;p&gt;Since I wanted to play with the WebSphere MQ, so when I failed to install the Perl Extension first time, I decided to install the server first on another machine. Somehow I managed to install the server. Then I tried to install the MQSeries Perl Extension, but to no avail. Even after installing the Client. Then I moved to another machine and did the whole this thing from scratch, and at last it worked &lt;img src="http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /&gt; &lt;/p&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1572547582182708302-1601188739942958368?l=mjawaids.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mjawaids.blogspot.com/feeds/1601188739942958368/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1572547582182708302&amp;postID=1601188739942958368' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/1601188739942958368'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/1601188739942958368'/><link rel='alternate' type='text/html' href='http://mjawaids.blogspot.com/2009/08/how-to-install-mqseries-perl-extension.html' title='How to install MQSeries Perl Extension for IBM WebSphere MQ'/><author><name>Jawaid</name><uri>http://www.blogger.com/profile/05875874113914026501</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1572547582182708302.post-2441434215379413766</id><published>2009-08-07T10:21:00.001+06:00</published><updated>2009-08-07T10:29:43.979+06:00</updated><title type='text'>Enable X Session over SSH</title><content type='html'>&lt;div class="snap_preview"&gt;&lt;p&gt;Sometimes there is a need to use the graphical X session on Linux machines but you cannot do so, since you don’t have access to the machine, you can just SSH it. But you can forward your X session over SSH. To do this use the -X option. If you are using &lt;a class="wpGallery" title="putty" href="http://www.putty.org/" target="_blank"&gt;putty &lt;/a&gt;then you can set the option like this. Go to:&lt;/p&gt; &lt;p&gt;&lt;em&gt;Connection -&gt; SSH -&gt; X11 -&gt; “Enable X11 forwarding”&lt;/em&gt;&lt;/p&gt; &lt;p&gt;This will enable X session over SSH on putty.&lt;/p&gt; &lt;p&gt;Enjoy the GUI &lt;img src="http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /&gt; &lt;/p&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1572547582182708302-2441434215379413766?l=mjawaids.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mjawaids.blogspot.com/feeds/2441434215379413766/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1572547582182708302&amp;postID=2441434215379413766' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/2441434215379413766'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/2441434215379413766'/><link rel='alternate' type='text/html' href='http://mjawaids.blogspot.com/2009/08/enable-x-session-over-ssh.html' title='Enable X Session over SSH'/><author><name>Jawaid</name><uri>http://www.blogger.com/profile/05875874113914026501</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1572547582182708302.post-5477043398490428343</id><published>2009-08-07T10:21:00.000+06:00</published><updated>2009-08-07T10:29:20.194+06:00</updated><title type='text'>How to setup PHP development environment in Eclipse?</title><content type='html'>&lt;div class="snap_preview"&gt;&lt;p&gt;As I am currently working on Joomla (&lt;a href="http://www.joomla.org/"&gt;http://www.joomla.org/&lt;/a&gt;) a CMS built in PHP, I came across a very nice tutorial about how to setup your development environment if you want to work on Joomla. Although the tutorial is specific to Joomla, PHP, and Eclipse, but in general it is a very good tutorial and one can learn how to setup a development environment for any project irrespective of technology used. Especially novice programmers will learn a lot from it.&lt;/p&gt; &lt;p&gt;Author first explained how to install and configure &lt;a href="http://www.apachefriends.org/en/xampp.html"&gt;XAMPP&lt;/a&gt;, then configure PHP and XDebug to debug the PHP applications. Then author explained how to install Eclipse, setup your workspace, configure it for debugging. Then author created a test project and ran it in debug mode. Then in the end author explained how to install and configure subclipse (Eclipse SVN plug-in) and how to import a project from SVN repository.&lt;/p&gt; &lt;p&gt;This is a very nice tutorial in general and specifically for those who work in Eclipse and PHP. Wanna read it? go ahead: &lt;a href="http://docs.joomla.org/Setting_up_your_workstation_for_Joomla%21_development"&gt;http://docs.joomla.org/Setting_up_your_workstation_for_Joomla!_development&lt;/a&gt;&lt;/p&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1572547582182708302-5477043398490428343?l=mjawaids.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mjawaids.blogspot.com/feeds/5477043398490428343/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1572547582182708302&amp;postID=5477043398490428343' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/5477043398490428343'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/5477043398490428343'/><link rel='alternate' type='text/html' href='http://mjawaids.blogspot.com/2009/08/how-to-setup-php-development.html' title='How to setup PHP development environment in Eclipse?'/><author><name>Jawaid</name><uri>http://www.blogger.com/profile/05875874113914026501</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1572547582182708302.post-5716799902744103768</id><published>2009-06-26T18:09:00.000+06:00</published><updated>2009-06-26T18:10:13.354+06:00</updated><title type='text'>Multiple MySQL on single host</title><content type='html'>&lt;div class="entrybody"&gt;    &lt;div class="snap_preview"&gt;&lt;p&gt;Sometimes we need to run multiple MySQL servers on single machine. That is mostly required in testing environments to test different aspects with different configurations. In this way one can test server without affecting others. So, if you want to run multiple MySQL you can use MySQL Sandbox which eases the whole process of installing and configuring the server. Here how will you do it.&lt;/p&gt; &lt;p&gt;First of all you need to install MySQL Sandbox. You can download it from &lt;a title="" rel="#someid0" href="https://launchpad.net/mysql-sandbox"&gt;https://launchpad.net/mysql-sandbox&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Then you need tar balls of MySQL server. You can download it from &lt;a rel="#someid1" href="http://www.mysql.com/"&gt;MySQL&lt;/a&gt; site.&lt;/p&gt; &lt;p&gt;After installing MySQL Sandbox you can run following script to install MySQL.&lt;/p&gt; &lt;p&gt;&lt;em&gt;make_sandbox  /path/to/mysql-X.X.XX-osinfo.tar.gz&lt;/em&gt;&lt;/p&gt; &lt;p&gt;This script will tell you some information like port, user name, and password which you can use to login to MySQL after installation. After confirmation it will install and run MySQL. That’s it! You are up and running.&lt;/p&gt; &lt;p&gt;If you want to install another MySQL you can just run the following command.&lt;/p&gt; &lt;p&gt;&lt;em&gt;make_sandbox  /path/to/mysql-X.X.XX-osinfo.tar.gz –check_port&lt;/em&gt;&lt;/p&gt; &lt;p&gt;The &lt;em&gt;–check_port&lt;/em&gt; option checks the first available port so it can install and run on that port. By default it will use the MySQL version as port. For example if you have MySQL version 4.1.20 it will run MySQL on port 4120. And if it is not available then it will try 4121.&lt;/p&gt; &lt;p&gt;MySQL Sandbox provides other useful scripts to manage the server. So installing and running multiple MySQL, even different versions, is that easy :) &lt;/p&gt; &lt;p&gt;You can find the complete documentation at &lt;a title="" rel="#someid2" href="http://forge.mysql.com/wiki/MySQL_Sandbox#Single_server_sandbox"&gt;http://forge.mysql.com/wiki/MySQL_Sandbox#Single_server_sandbox&lt;/a&gt;.&lt;/p&gt; &lt;/div&gt;     &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1572547582182708302-5716799902744103768?l=mjawaids.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mjawaids.blogspot.com/feeds/5716799902744103768/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1572547582182708302&amp;postID=5716799902744103768' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/5716799902744103768'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/5716799902744103768'/><link rel='alternate' type='text/html' href='http://mjawaids.blogspot.com/2009/06/multiple-mysql-on-single-host.html' title='Multiple MySQL on single host'/><author><name>Jawaid</name><uri>http://www.blogger.com/profile/05875874113914026501</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1572547582182708302.post-5501860240482818018</id><published>2009-06-26T18:07:00.001+06:00</published><updated>2009-06-26T18:07:44.944+06:00</updated><title type='text'>MySQL Query Cache</title><content type='html'>&lt;p style="color: rgb(0, 0, 0);"&gt;MySQL query cache is good to cache select queries and their results and improve some performance of your database applications. So I thought I should write a quick tutorial to quickly set up the query cache without going into the details. So here what you have to do to enable query cache on MySQL.&lt;/p&gt; &lt;p style="color: rgb(0, 0, 0);"&gt;If you want to enable query cache without restarting the MySQL server then just run the following command on MySQL prompt/client:&lt;/p&gt; &lt;p style="margin: 0pt; font-family: Calibri; font-size: 11pt; color: rgb(0, 0, 0);"&gt;&lt;em&gt;set global query_cache_size=67108864;&lt;/em&gt;&lt;/p&gt; &lt;p style="margin: 0pt; font-family: Calibri; font-size: 11pt; color: rgb(0, 0, 0);"&gt;&lt;em&gt;&lt;br /&gt;&lt;/em&gt; &lt;/p&gt; &lt;p style="margin: 0pt; font-family: Calibri; font-size: 11pt; color: rgb(0, 0, 0);"&gt;This will set MySQL query cache size to around 64MB and also enable the query cache. You can set it to any value you desire. You can then check the status later by running following commands on MySQL prompt/client:&lt;/p&gt;&lt;p style="margin: 0pt; font-family: Calibri; font-size: 11pt; color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0pt; font-family: Calibri; font-size: 11pt; color: rgb(0, 0, 0);"&gt; &lt;/p&gt;&lt;p style="margin: 0pt; font-family: Calibri; font-size: 11pt; color: rgb(0, 0, 0);"&gt; &lt;/p&gt;&lt;p style="margin: 0pt; font-family: Calibri; font-size: 11pt; color: rgb(0, 0, 0);"&gt;&lt;em&gt;SHOW VARIABLES LIKE ‘%query_cache%’;&lt;/em&gt;&lt;/p&gt; &lt;p style="margin: 0pt; font-family: Calibri; font-size: 11pt; color: rgb(0, 0, 0);"&gt;&lt;em&gt;SHOW STATUS LIKE ‘%qcache%’;&lt;/em&gt;&lt;/p&gt; &lt;p style="margin: 0pt; font-family: Calibri; font-size: 11pt; color: rgb(0, 0, 0);"&gt;&lt;em&gt;&lt;br /&gt;&lt;/em&gt; &lt;/p&gt; &lt;p style="margin: 0pt; font-family: Calibri; font-size: 11pt; color: rgb(0, 0, 0);"&gt;These commands will show some useful information about the query cache like if query cache is enabled, how much memory is being used, how many queries are currently in cache, cache hit rate etc.&lt;/p&gt; &lt;p style="margin: 0pt; font-family: Calibri; font-size: 11pt; color: rgb(0, 0, 0);"&gt; &lt;/p&gt;&lt;p style="margin: 0pt; font-family: Calibri; font-size: 11pt; color: rgb(0, 0, 0);"&gt;This is really a quick way to enable query cache. For details see MySQL documentation &lt;a title="" rel="#someid0" href="http://dev.mysql.com/tech-resources/articles/mysql-query-cache.html"&gt;http://dev.mysql.com/tech-resources/articles/mysql-query-cache.html&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1572547582182708302-5501860240482818018?l=mjawaids.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mjawaids.blogspot.com/feeds/5501860240482818018/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1572547582182708302&amp;postID=5501860240482818018' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/5501860240482818018'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/5501860240482818018'/><link rel='alternate' type='text/html' href='http://mjawaids.blogspot.com/2009/06/mysql-query-cache.html' title='MySQL Query Cache'/><author><name>Jawaid</name><uri>http://www.blogger.com/profile/05875874113914026501</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1572547582182708302.post-7892988494470594391</id><published>2009-06-26T18:06:00.001+06:00</published><updated>2009-06-26T18:06:55.615+06:00</updated><title type='text'>CVS account change in Eclipse</title><content type='html'>&lt;p&gt;We were setting up new development environment for our team using eclipse and checked out the code from CVS. At the end we faced an issue when we tested how other developers will change the CVS account to their own one. Eclipse was not allowing us to change the CVS account. Then I found that we have to change the account in CVS meta files. The command I used to replace the account was :&lt;/p&gt; &lt;p&gt;&lt;em&gt;find . -regex .*CVS/Root -print0 | xargs -0 perl -p -i.orig -e “s/&lt;/em&gt;olduser&lt;em&gt;/&lt;/em&gt;newuser&lt;em&gt;/;”&lt;/em&gt;&lt;/p&gt; &lt;p&gt;This replaced the CVS user name in all CVS meta files in the whole project hierarchy &lt;img src="http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /&gt; &lt;em&gt;&lt;br /&gt;&lt;/em&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1572547582182708302-7892988494470594391?l=mjawaids.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mjawaids.blogspot.com/feeds/7892988494470594391/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1572547582182708302&amp;postID=7892988494470594391' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/7892988494470594391'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/7892988494470594391'/><link rel='alternate' type='text/html' href='http://mjawaids.blogspot.com/2009/06/cvs-account-change-in-eclipse.html' title='CVS account change in Eclipse'/><author><name>Jawaid</name><uri>http://www.blogger.com/profile/05875874113914026501</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1572547582182708302.post-5659141373899076303</id><published>2009-05-25T17:22:00.001+06:00</published><updated>2009-05-25T17:42:00.460+06:00</updated><title type='text'>Let's code bad!</title><content type='html'>&lt;div class="entrybody"&gt;    &lt;div class="snap_preview"&gt;&lt;p&gt;I was reading the book &lt;em&gt;Clean Code – A Handbook of Agile Software Craftsmanship&lt;/em&gt;, Rober C. Martin Series. A section in chapter one caught my attention and remind me of code and reasons that I got for writing bad code and designing bad solution. Now I think this is a good argument against it which I am quoting here from the book.&lt;/p&gt; &lt;p&gt;&lt;em&gt;“Have you ever waded through a mess so grave that it took weeks to do what should have taken hours? Have you seen what should have been a one-line change, made instead in hundreds of different modules? These symptoms are all too common. Why does this happen to code? Why does good code rot so quickly into bad code? We have lots of explanations for it. &lt;strong&gt;We complain that the requirements changed in ways that thwart the original design. We bemoan the schedules that were too tight to do things right.&lt;/strong&gt;&lt;br /&gt;We blather about stupid managers and intolerant customers and useless marketing types and telephone sanitizers. &lt;strong&gt;But the fault, dear Dilbert, is not in our stars, but in ourselves. We are unprofessional.&lt;/strong&gt;&lt;br /&gt;This may be a bitter pill to swallow. How could this mess be our fault? What about the requirements? What about the schedule? What about the stupid managers and the useless marketing types? Don’t they bear some of the blame?&lt;br /&gt;No. The managers and marketers look to us for the information they need to make promises and commitments; and even when they don’t look to us, we should not be shy about telling them what we think. The users look to us to validate the way the requirements&lt;br /&gt;will fit into the system. The project managers look to us to help work out the schedule. We are deeply complicit in the planning of the project and share a great deal of the responsibility for any failures; especially if those failures have to do with bad code! &lt;strong&gt;“But wait!” you say. “If I don’t do what my manager says, I’ll be fired.” Probably not.&lt;/strong&gt; Most managers want the truth, even when they don’t act like it. Most managers want good code, even when they are obsessing about the schedule. They may defend the schedule and requirements with passion; but that’s their job. It’s your job to defend the code with equal passion.&lt;br /&gt;&lt;strong&gt;To drive this point home, what if you were a doctor and had a patient who demanded that you stop all the silly and-washing in preparation for surgery because it was taking too much time?2 Clearly the patient is the boss; and yet the doctor should absolutely refuse to comply. Why? Because the doctor knows more than the patient about the risks of disease and infection. It would be unprofessional (never mind criminal) for the doctor to comply with the patient.&lt;/strong&gt;&lt;br /&gt;So too it is unprofessional for programmers to bend to the will of managers who don’t understand the risks of making messes.”&lt;/em&gt;&lt;/p&gt; &lt;/div&gt;     &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1572547582182708302-5659141373899076303?l=mjawaids.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mjawaids.blogspot.com/feeds/5659141373899076303/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1572547582182708302&amp;postID=5659141373899076303' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/5659141373899076303'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/5659141373899076303'/><link rel='alternate' type='text/html' href='http://mjawaids.blogspot.com/2009/05/lets-code-bad.html' title='Let&apos;s code bad!'/><author><name>Jawaid</name><uri>http://www.blogger.com/profile/05875874113914026501</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1572547582182708302.post-3855473839073479250</id><published>2009-04-22T12:31:00.001+06:00</published><updated>2009-04-22T12:33:04.496+06:00</updated><title type='text'>Breaking problem into code</title><content type='html'>&lt;div class="entrybody"&gt;    &lt;div class="snap_preview"&gt;&lt;p&gt;Let us consider an example. If you have two boxes say BoxA and BoxB, and there are few balls of different colors, let’s say 5 balls (red, blue, green, yellow, and white) in BoxA, and you want to move one ball, say red ball from BoxA to BoxB. What will be the steps? If you can make a flow chart of it then its good, but if you find it difficult to make a flow chart of it then you need to do some hard work to become a programmer.&lt;/p&gt; &lt;p&gt;I asked this to someone and guess how he solved it. Here is his solution. Take out all balls from BoxA, then pick the red ball, put it in BoxB, and then put all remaining balls back in BoxA.&lt;/p&gt; &lt;p&gt;Fine! it worked. But why would you take out all balls if you can only take out red ball and move it to next box?&lt;/p&gt; &lt;p&gt;Let’s move this to programming side. In the above mentioned scenario we will have two database tables, boxes, and balls. boxes will have boxid as PK, name, and other details. Keep it simple so we don’t get lost in other details. balls table has ballid as PK, name, boxid as FK, and other details. boxes table has two records with 1 and BoxA as its boxid and name. balls table will have 5 records with id between 1 to 5 and red, blue, green, yellow, and white as their names, and all balls will have 1 in boxid field which is FK to boxes table.&lt;/p&gt; &lt;p&gt;Now if we adopt the first solution then it will run following queries (these are pseudo queries not actual SQL queries):&lt;/p&gt; &lt;p&gt;  - select all balls where boxid=1 (so we can have a list of all balls before deleting them from database)&lt;br /&gt;  - delete from balls where boxid=1&lt;br /&gt;  - insert into balls values ballid=1, name=red ball, boxid=2&lt;br /&gt;  - insert into balls values&lt;br /&gt;        (ballid=2, name=blue ball, boxid=1)&lt;br /&gt;        (ballid=3, name=green ball, boxid=1)&lt;br /&gt;        (ballid=4, name=yellow ball, boxid=1)&lt;br /&gt;        (ballid=5, name=white ball, boxid=1)&lt;/p&gt; &lt;p&gt;Or even worse if we use multiple insert queries. It will run from 4 to 7 queries.&lt;/p&gt; &lt;p&gt;Now let’s see what happens if we just perform operation on the red ball and don’t touch other balls. &lt;/p&gt; &lt;p&gt;  - update balls set boxid=2 where ballid=1; /* ball with id 1 is the red ball */&lt;/p&gt; &lt;p&gt;Wow, just one query and we’re done! We saved 3 to 6 queries. Imagine this scenario for a high traffic website or any other application, we can improve the performance with a big difference by just implementing correct logic to solve a problem.&lt;/p&gt; &lt;/div&gt;     &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1572547582182708302-3855473839073479250?l=mjawaids.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://mjawaid.wordpress.com/2009/04/22/breaking-problem-into-code/' title='Breaking problem into code'/><link rel='replies' type='application/atom+xml' href='http://mjawaids.blogspot.com/feeds/3855473839073479250/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1572547582182708302&amp;postID=3855473839073479250' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/3855473839073479250'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/3855473839073479250'/><link rel='alternate' type='text/html' href='http://mjawaids.blogspot.com/2009/04/breaking-problem-into-code.html' title='Breaking problem into code'/><author><name>Jawaid</name><uri>http://www.blogger.com/profile/05875874113914026501</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1572547582182708302.post-1295141618778678815</id><published>2009-04-17T12:56:00.002+06:00</published><updated>2009-04-17T15:52:19.775+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='locks'/><category scheme='http://www.blogger.com/atom/ns#' term='indexing'/><category scheme='http://www.blogger.com/atom/ns#' term='indexes'/><category scheme='http://www.blogger.com/atom/ns#' term='database design'/><category scheme='http://www.blogger.com/atom/ns#' term='locking'/><category scheme='http://www.blogger.com/atom/ns#' term='db design'/><category scheme='http://www.blogger.com/atom/ns#' term='database'/><category scheme='http://www.blogger.com/atom/ns#' term='db'/><title type='text'>Database indexes and locks</title><content type='html'>&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:trackmoves/&gt;   &lt;w:trackformatting/&gt;   &lt;w:punctuationkerning/&gt;   &lt;w:validateagainstschemas/&gt;   &lt;w:saveifxmlinvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;   &lt;w:ignoremixedcontent&gt;false&lt;/w:IgnoreMixedContent&gt;   &lt;w:alwaysshowplaceholdertext&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;   &lt;w:donotpromoteqf/&gt;   &lt;w:lidthemeother&gt;EN-US&lt;/w:LidThemeOther&gt;   &lt;w:lidthemeasian&gt;X-NONE&lt;/w:LidThemeAsian&gt;   &lt;w:lidthemecomplexscript&gt;X-NONE&lt;/w:LidThemeComplexScript&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;    &lt;w:dontgrowautofit/&gt;    &lt;w:splitpgbreakandparamark/&gt;    &lt;w:dontvertaligncellwithsp/&gt;    &lt;w:dontbreakconstrainedforcedtables/&gt;    &lt;w:dontvertalignintxbx/&gt;    &lt;w:word11kerningpairs/&gt;    &lt;w:cachedcolbalance/&gt;   &lt;/w:Compatibility&gt;   &lt;m:mathpr&gt;    &lt;m:mathfont val="Cambria Math"&gt;    &lt;m:brkbin val="before"&gt;    &lt;m:brkbinsub val="&amp;#45;-"&gt;    &lt;m:smallfrac val="off"&gt;    &lt;m:dispdef/&gt;    &lt;m:lmargin val="0"&gt;    &lt;m:rmargin val="0"&gt;    &lt;m:defjc val="centerGroup"&gt;    &lt;m:wrapindent val="1440"&gt;    &lt;m:intlim val="subSup"&gt;    &lt;m:narylim val="undOvr"&gt;   &lt;/m:mathPr&gt;&lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:latentstyles deflockedstate="false" defunhidewhenused="true" defsemihidden="true" defqformat="false" defpriority="99" latentstylecount="267"&gt;   &lt;w:lsdexception locked="false" priority="0" semihidden="false" unhidewhenused="false" qformat="true" name="Normal"&gt;   &lt;w:lsdexception locked="false" priority="9" semihidden="false" unhidewhenused="false" qformat="true" name="heading 1"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 2"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 3"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 4"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 5"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 6"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 7"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 8"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 9"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 1"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 2"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 3"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 4"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 5"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 6"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 7"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 8"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 9"&gt;   &lt;w:lsdexception locked="false" priority="35" qformat="true" name="caption"&gt;   &lt;w:lsdexception locked="false" priority="10" semihidden="false" unhidewhenused="false" qformat="true" name="Title"&gt;   &lt;w:lsdexception locked="false" priority="1" name="Default Paragraph Font"&gt;   &lt;w:lsdexception locked="false" priority="11" semihidden="false" unhidewhenused="false" qformat="true" name="Subtitle"&gt;   &lt;w:lsdexception locked="false" priority="22" semihidden="false" unhidewhenused="false" qformat="true" name="Strong"&gt;   &lt;w:lsdexception locked="false" priority="20" semihidden="false" unhidewhenused="false" qformat="true" name="Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="59" semihidden="false" unhidewhenused="false" name="Table Grid"&gt;   &lt;w:lsdexception locked="false" unhidewhenused="false" name="Placeholder Text"&gt;   &lt;w:lsdexception locked="false" priority="1" semihidden="false" unhidewhenused="false" qformat="true" name="No Spacing"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" unhidewhenused="false" name="Revision"&gt;   &lt;w:lsdexception locked="false" priority="34" semihidden="false" unhidewhenused="false" qformat="true" name="List Paragraph"&gt;   &lt;w:lsdexception locked="false" priority="29" semihidden="false" unhidewhenused="false" qformat="true" name="Quote"&gt;   &lt;w:lsdexception locked="false" priority="30" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Quote"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="19" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="21" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="31" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Reference"&gt;   &lt;w:lsdexception locked="false" priority="32" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Reference"&gt;   &lt;w:lsdexception locked="false" priority="33" semihidden="false" unhidewhenused="false" qformat="true" name="Book Title"&gt;   &lt;w:lsdexception locked="false" priority="37" name="Bibliography"&gt;   &lt;w:lsdexception locked="false" priority="39" qformat="true" name="TOC Heading"&gt;  &lt;/w:LatentStyles&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;style&gt; &lt;!--  /* Font Definitions */  @font-face  {font-family:Wingdings;  panose-1:5 0 0 0 0 0 0 0 0 0;  mso-font-charset:2;  mso-generic-font-family:auto;  mso-font-pitch:variable;  mso-font-signature:0 268435456 0 0 -2147483648 0;} @font-face  {font-family:"Cambria Math";  panose-1:2 4 5 3 5 4 6 3 2 4;  mso-font-charset:0;  mso-generic-font-family:roman;  mso-font-pitch:variable;  mso-font-signature:-1610611985 1107304683 0 0 159 0;} @font-face  {font-family:Calibri;  panose-1:2 15 5 2 2 2 4 3 2 4;  mso-font-charset:0;  mso-generic-font-family:swiss;  mso-font-pitch:variable;  mso-font-signature:-1610611985 1073750139 0 0 159 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal  {mso-style-unhide:no;  mso-style-qformat:yes;  mso-style-parent:"";  margin-top:0in;  margin-right:0in;  margin-bottom:10.0pt;  margin-left:0in;  line-height:115%;  mso-pagination:widow-orphan;  font-size:11.0pt;  font-family:"Calibri","sans-serif";  mso-ascii-font-family:Calibri;  mso-ascii-theme-font:minor-latin;  mso-fareast-font-family:Calibri;  mso-fareast-theme-font:minor-latin;  mso-hansi-font-family:Calibri;  mso-hansi-theme-font:minor-latin;  mso-bidi-font-family:"Times New Roman";  mso-bidi-theme-font:minor-bidi;} a:link, span.MsoHyperlink  {mso-style-priority:99;  color:blue;  mso-themecolor:hyperlink;  text-decoration:underline;  text-underline:single;} a:visited, span.MsoHyperlinkFollowed  {mso-style-noshow:yes;  mso-style-priority:99;  color:purple;  mso-themecolor:followedhyperlink;  text-decoration:underline;  text-underline:single;} code  {mso-style-noshow:yes;  mso-style-priority:99;  font-family:"Courier New";  mso-ascii-font-family:"Courier New";  mso-fareast-font-family:"Times New Roman";  mso-hansi-font-family:"Courier New";  mso-bidi-font-family:"Courier New";} p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph  {mso-style-priority:34;  mso-style-unhide:no;  mso-style-qformat:yes;  margin-top:0in;  margin-right:0in;  margin-bottom:10.0pt;  margin-left:.5in;  mso-add-space:auto;  line-height:115%;  mso-pagination:widow-orphan;  font-size:11.0pt;  font-family:"Calibri","sans-serif";  mso-ascii-font-family:Calibri;  mso-ascii-theme-font:minor-latin;  mso-fareast-font-family:Calibri;  mso-fareast-theme-font:minor-latin;  mso-hansi-font-family:Calibri;  mso-hansi-theme-font:minor-latin;  mso-bidi-font-family:"Times New Roman";  mso-bidi-theme-font:minor-bidi;} p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst  {mso-style-priority:34;  mso-style-unhide:no;  mso-style-qformat:yes;  mso-style-type:export-only;  margin-top:0in;  margin-right:0in;  margin-bottom:0in;  margin-left:.5in;  margin-bottom:.0001pt;  mso-add-space:auto;  line-height:115%;  mso-pagination:widow-orphan;  font-size:11.0pt;  font-family:"Calibri","sans-serif";  mso-ascii-font-family:Calibri;  mso-ascii-theme-font:minor-latin;  mso-fareast-font-family:Calibri;  mso-fareast-theme-font:minor-latin;  mso-hansi-font-family:Calibri;  mso-hansi-theme-font:minor-latin;  mso-bidi-font-family:"Times New Roman";  mso-bidi-theme-font:minor-bidi;} p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle  {mso-style-priority:34;  mso-style-unhide:no;  mso-style-qformat:yes;  mso-style-type:export-only;  margin-top:0in;  margin-right:0in;  margin-bottom:0in;  margin-left:.5in;  margin-bottom:.0001pt;  mso-add-space:auto;  line-height:115%;  mso-pagination:widow-orphan;  font-size:11.0pt;  font-family:"Calibri","sans-serif";  mso-ascii-font-family:Calibri;  mso-ascii-theme-font:minor-latin;  mso-fareast-font-family:Calibri;  mso-fareast-theme-font:minor-latin;  mso-hansi-font-family:Calibri;  mso-hansi-theme-font:minor-latin;  mso-bidi-font-family:"Times New Roman";  mso-bidi-theme-font:minor-bidi;} p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast  {mso-style-priority:34;  mso-style-unhide:no;  mso-style-qformat:yes;  mso-style-type:export-only;  margin-top:0in;  margin-right:0in;  margin-bottom:10.0pt;  margin-left:.5in;  mso-add-space:auto;  line-height:115%;  mso-pagination:widow-orphan;  font-size:11.0pt;  font-family:"Calibri","sans-serif";  mso-ascii-font-family:Calibri;  mso-ascii-theme-font:minor-latin;  mso-fareast-font-family:Calibri;  mso-fareast-theme-font:minor-latin;  mso-hansi-font-family:Calibri;  mso-hansi-theme-font:minor-latin;  mso-bidi-font-family:"Times New Roman";  mso-bidi-theme-font:minor-bidi;} .MsoChpDefault  {mso-style-type:export-only;  mso-default-props:yes;  mso-ascii-font-family:Calibri;  mso-ascii-theme-font:minor-latin;  mso-fareast-font-family:Calibri;  mso-fareast-theme-font:minor-latin;  mso-hansi-font-family:Calibri;  mso-hansi-theme-font:minor-latin;  mso-bidi-font-family:"Times New Roman";  mso-bidi-theme-font:minor-bidi;} .MsoPapDefault  {mso-style-type:export-only;  margin-bottom:10.0pt;  line-height:115%;} @page Section1  {size:8.5in 11.0in;  margin:1.0in 1.0in 1.0in 1.0in;  mso-header-margin:.5in;  mso-footer-margin:.5in;  mso-paper-source:0;} div.Section1  {page:Section1;}  /* List Definitions */  @list l0  {mso-list-id:987050918;  mso-list-type:hybrid;  mso-list-template-ids:543331610 -695824068 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;} @list l0:level1  {mso-level-start-at:0;  mso-level-number-format:bullet;  mso-level-text:-;  mso-level-tab-stop:none;  mso-level-number-position:left;  text-indent:-.25in;  font-family:"Calibri","sans-serif";  mso-fareast-font-family:Calibri;  mso-fareast-theme-font:minor-latin;  mso-bidi-font-family:"Times New Roman";  mso-bidi-theme-font:minor-bidi;} @list l1  {mso-list-id:2035501307;  mso-list-type:hybrid;  mso-list-template-ids:165604188 -695824068 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;} @list l1:level1  {mso-level-start-at:0;  mso-level-number-format:bullet;  mso-level-text:-;  mso-level-tab-stop:none;  mso-level-number-position:left;  margin-left:.75in;  text-indent:-.25in;  font-family:"Calibri","sans-serif";  mso-fareast-font-family:Calibri;  mso-fareast-theme-font:minor-latin;  mso-bidi-font-family:"Times New Roman";  mso-bidi-theme-font:minor-bidi;} ol  {margin-bottom:0in;} ul  {margin-bottom:0in;} --&gt; &lt;/style&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable  {mso-style-name:"Table Normal";  mso-tstyle-rowband-size:0;  mso-tstyle-colband-size:0;  mso-style-noshow:yes;  mso-style-priority:99;  mso-style-qformat:yes;  mso-style-parent:"";  mso-padding-alt:0in 5.4pt 0in 5.4pt;  mso-para-margin-top:0in;  mso-para-margin-right:0in;  mso-para-margin-bottom:10.0pt;  mso-para-margin-left:0in;  line-height:115%;  mso-pagination:widow-orphan;  font-size:11.0pt;  font-family:"Calibri","sans-serif";  mso-ascii-font-family:Calibri;  mso-ascii-theme-font:minor-latin;  mso-hansi-font-family:Calibri;  mso-hansi-theme-font:minor-latin;} &lt;/style&gt; &lt;![endif]--&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;I was discussing with my friend on the issue I have discussed in my post Referential Integrity (&lt;a href="http://mjawaids.blogspot.com/2009/04/referential-integrity.html"&gt;http://mjawaids.blogspot.com/2009/04/referential-integrity.html&lt;/a&gt;) and Mapping tables (&lt;a href="http://mjawaids.blogspot.com/2009/04/mapping-tables.html"&gt;http://mjawaids.blogspot.com/2009/04/mapping-tables.html&lt;/a&gt;). My friend told me the scenario that when we create multiple indexes on the table we will get deadlocks. The reason he told me was the bucket lock, or in other words gap lock. Actually what server does is that due to multiple indexes when you lock any one record it locks multiple records, since it searches indexes and all the records it encounters during search, it locks them. That what I understood he was trying to say. I wasn’t convinced and thought of trying to create few tables with indexes and test them. For test I used MySQL4 and InnoDB engine, since the issue we were facing was on it.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;So I created five tables &lt;i style=""&gt;indxtest1, indxtest2, indxtest3, indxtest4&lt;/i&gt;, and &lt;i style=""&gt;indxtest5&lt;/i&gt;.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;CREATE TABLE `indxtest1` (&lt;span style=""&gt;                &lt;/span&gt;&lt;span style=""&gt;                                              &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;`id` bigint(20) NOT NULL auto_increment,&lt;span style=""&gt;                                              &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;`name` varchar(255) default NULL,&lt;span style=""&gt;                                                     &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;         &lt;/span&gt;&lt;span style=""&gt;    &lt;/span&gt;`fk` bigint(20) default NULL,&lt;span style=""&gt;                                                         &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;PRIMARY KEY&lt;span style=""&gt;  &lt;/span&gt;(`id`)&lt;span style=""&gt;                                                                   &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;           &lt;/span&gt;) ENGINE=InnoDB DEFAULT CHARSET=latin1 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC&lt;span style=""&gt;  &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;CREATE TABLE `indxtest2` (&lt;span style=""&gt;                                                              &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;`id` bigint(20) NOT NULL auto_increment,&lt;span style=""&gt;                                              &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;`name` varchar(255) default NULL,&lt;span style=""&gt;                                                     &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;`fk` bigint(20) default NULL,&lt;span style=""&gt;                                                         &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;PRIMARY KEY&lt;span style=""&gt;  &lt;/span&gt;(`id`),&lt;span style=""&gt;                                                       &lt;/span&gt;&lt;span style=""&gt;           &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;KEY `NewIndex1` (`fk`)&lt;span style=""&gt;                                                                &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;           &lt;/span&gt;) ENGINE=InnoDB DEFAULT CHARSET=latin1 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC&lt;span style=""&gt;  &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;CREATE TABLE `indxtest3` (&lt;span style=""&gt;                  &lt;/span&gt;&lt;span style=""&gt;                                            &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;`id` bigint(20) NOT NULL auto_increment,&lt;span style=""&gt;                                              &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;`name` varchar(255) default NULL,&lt;span style=""&gt;                                                     &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;           &lt;/span&gt;&lt;span style=""&gt;  &lt;/span&gt;`fk` bigint(20) default NULL,&lt;span style=""&gt;                                                         &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;PRIMARY KEY&lt;span style=""&gt;  &lt;/span&gt;(`id`),&lt;span style=""&gt;                                                                  &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;KEY `NewIndex1` (`id`,`fk`)&lt;span style=""&gt;                           &lt;/span&gt;&lt;span style=""&gt;                                &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;           &lt;/span&gt;) ENGINE=InnoDB DEFAULT CHARSET=latin1 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC&lt;span style=""&gt;  &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;CREATE TABLE `indxtest4` (&lt;span style=""&gt;                                                              &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;`id` bigint(20) NOT NULL auto_increment,&lt;span style=""&gt;                                              &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;`name` varchar(255) default NULL,&lt;span style=""&gt;                                                     &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;`fk` bigint(20) NOT NULL default '0',&lt;span style=""&gt;                                        &lt;/span&gt;&lt;span style=""&gt;         &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;PRIMARY KEY&lt;span style=""&gt;  &lt;/span&gt;(`id`,`fk`)&lt;span style=""&gt;                                                              &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;           &lt;/span&gt;) ENGINE=InnoDB DEFAULT CHARSET=latin1 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC&lt;span style=""&gt;  &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;CREATE TABLE `indxtest5` (&lt;span style=""&gt;                                                                             &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;`id` bigint(20) NOT NULL auto_increment,&lt;span style=""&gt;                                                             &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;`name` varchar(255) default NULL,&lt;span style=""&gt;                                                                    &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;`fk` bigint(20) default NULL,&lt;span style=""&gt;                                                                        &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;PRIMARY KEY&lt;span style=""&gt;  &lt;/span&gt;(`id`),&lt;span style=""&gt;                              &lt;/span&gt;&lt;span style=""&gt;                                                   &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;KEY `FK_indxtest4` (`fk`),&lt;span style=""&gt;                                                                           &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;             &lt;/span&gt;CONSTRAINT `FK_indxtest4` FOREIGN KEY (`fk`) REFERENCES `indxtest5parent` (`id`) ON DELETE SET NULL&lt;span style=""&gt;  &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;           &lt;/span&gt;) ENGINE=InnoDB DEFAULT CHARSET=latin1 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC&lt;span style=""&gt;           &lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;And another table &lt;i style=""&gt;indxtest5parent&lt;/i&gt; as parent for &lt;i style=""&gt;indxtest5&lt;/i&gt;.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;CREATE TABLE `indxtest5parent` (&lt;span style=""&gt;                        &lt;/span&gt;&lt;span style=""&gt;                                &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;                   &lt;/span&gt;`id` bigint(20) NOT NULL auto_increment,&lt;span style=""&gt;                                              &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;                   &lt;/span&gt;`test` varchar(255) default NULL,&lt;span style=""&gt;                                                     &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;           &lt;/span&gt;&lt;span style=""&gt;        &lt;/span&gt;PRIMARY KEY&lt;span style=""&gt;  &lt;/span&gt;(`id`)&lt;span style=""&gt;                                                                   &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%; color: rgb(79, 129, 189);font-size:10;" &gt;&lt;span style=""&gt;                 &lt;/span&gt;) ENGINE=InnoDB DEFAULT CHARSET=latin1 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC&lt;span style=""&gt;  &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;Let me explain what is the difference between the tables. All tables except the &lt;i style=""&gt;indxtest5parent&lt;/i&gt; contain three fields: &lt;i style=""&gt;id, name&lt;/i&gt;, and &lt;i style=""&gt;fk&lt;/i&gt;. Don’t confuse &lt;i style=""&gt;fk&lt;/i&gt; with a foreign key. &lt;i style=""&gt;Id&lt;/i&gt; is the primary key in all tables. The main difference between the tables is the indexing on the &lt;i style=""&gt;fk&lt;/i&gt; field. &lt;/p&gt;  &lt;p class="MsoListParagraphCxSpFirst" style="text-align: justify; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;-&lt;span style=";font-family:&amp;quot;;font-size:7;"  &gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;The &lt;i style=""&gt;indxtest1&lt;/i&gt; has no index on &lt;i style=""&gt;fk&lt;/i&gt;.&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="text-align: justify; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;-&lt;span style=";font-family:&amp;quot;;font-size:7;"  &gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;The &lt;i style=""&gt;indxtest2&lt;/i&gt; has an index on &lt;i style=""&gt;fk&lt;/i&gt;, so &lt;i style=""&gt;fk&lt;/i&gt; is indexed.&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="text-align: justify; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;-&lt;span style=";font-family:&amp;quot;;font-size:7;"  &gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;The &lt;i style=""&gt;indxtest3&lt;/i&gt; has a multi-field-index on &lt;i style=""&gt;id&lt;/i&gt; and&lt;i style=""&gt; fk&lt;/i&gt; combined, in addition to primary key index on &lt;i style=""&gt;id.&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="text-align: justify; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;-&lt;span style=";font-family:&amp;quot;;font-size:7;"  &gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;The &lt;i style=""&gt;indxtest4&lt;/i&gt; has a composite primary key &lt;i style=""&gt;id, fk&lt;/i&gt;. Therefore there is a primary key index on &lt;i style=""&gt;id&lt;/i&gt; and &lt;i style=""&gt;fk&lt;/i&gt; i.e multi-field-index.&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpLast" style="text-align: justify; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;-&lt;span style=";font-family:&amp;quot;;font-size:7;"  &gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;The &lt;i style=""&gt;indxtest5&lt;/i&gt; has a foreign key &lt;i style=""&gt;fk&lt;/i&gt; mapping to &lt;i style=""&gt;id&lt;/i&gt; field of &lt;i style=""&gt;indxtest5parent&lt;/i&gt;. So it has foreign key index on &lt;i style=""&gt;fk&lt;/i&gt;.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;After that I inserted some data in these tables, around just 10 records. I inserted that few records since I wasn’t testing performance with huge data, instead I was just testing that how records are searched in table with indexes, multiple indexes, and without indexes, which is useful in knowing how records are locked, implicitly when updating or explicitly.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;So all tables look almost like this after inserting data:&lt;/p&gt;  &lt;table class="MsoNormalTable" style="" border="1" cellpadding="0"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 0.75pt; background: silver none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;id&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; background: silver none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;name&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; background: silver none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;fk&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;One&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;10&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;2&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;Two&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;12&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;3&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;three&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;13&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;4&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;Four&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;14&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;5&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;Five&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;15&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;Six&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;15&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;7&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;seven&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;14&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;8&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;eight&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;13&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;9&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;Nine&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;12&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;10&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;Ten&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;" valign="top"&gt;   &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;10&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;Now run the following queries on all tables:&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpFirst" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;select * from indxtest1 where id = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;select * from indxtest2 where id = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;select * from indxtest3 where id = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;select * from indxtest4 where id = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpLast" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;select * from indxtest5 where id = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;These all queries will result in same output, i.e the first record of the table. This is very simple, and since result was filtered using the primary key in the where clause so it scanned only one record during search. We can see this by running following queries:&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpFirst" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;explain select * from indxtest1 where id = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;explain select * from indxtest2 where id = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;explain select * from indxtest3 where id = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;explain select * from indxtest4 where id = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpLast" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;explain select * from indxtest5 where id = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;You will notice that in result the &lt;i style=""&gt;rows&lt;/i&gt; column will show 1, that means only one record was scanned during the search.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;Now let’s filter the result using the fk field in the where clause:&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpFirst" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;select * from indxtest1 where fk = 10;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;select * from indxtest2 where fk = 10;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;select * from indxtest3 where fk = 10;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;select * from indxtest4 where fk = 10;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpLast" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;select * from indxtest5 where fk = 10;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;All these queries will return the same result, two records with id in 1 and 10. But how many records were scanned during search? To find out the answer run the following queries:&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpFirst" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;explain select * from indxtest1 where fk = 10;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;explain select * from indxtest2 where fk = 10;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;explain select * from indxtest3 where fk = 10;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;explain select * from indxtest4 where fk = 10;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpLast" style="text-align: justify;"&gt;&lt;span style="color: rgb(79, 129, 189);"&gt;explain select * from indxtest5 where fk = 10;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;In the &lt;i style=""&gt;rows&lt;/i&gt; column you will notice that for the &lt;i style=""&gt;indxtest1&lt;/i&gt; table it scanned 10 records. That is reasonable since there was no indexing. Now let’s see for &lt;i style=""&gt;indxtest2&lt;/i&gt; table, 2 records were scanned. This is also reasonable since &lt;i style=""&gt;fk&lt;/i&gt; was indexed. So far so good. Now for &lt;i style=""&gt;indxtest3&lt;/i&gt; table 10 records were scanned. Hmm… ok we will discuss this in a moment. Let’s check other queries first. For &lt;i style=""&gt;indxtest4&lt;/i&gt; table 10 records were scanned, and for &lt;i style=""&gt;indxtest5&lt;/i&gt; table only 2 records were scanned. Result for &lt;i style=""&gt;indxtest5&lt;/i&gt; table is also reasonable since it has a foreign key index on it.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;Now what are the cases with &lt;i style=""&gt;indxtest3&lt;/i&gt; and &lt;i style=""&gt;indxtest4&lt;/i&gt;? If you notice both tables have a multi-column index. According to MySQL documentation:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.5in; text-align: justify;"&gt;&lt;i style=""&gt;MySQL uses multiple-column indexes in such a way that queries are fast when you specify a known quantity for the first column of the index in a &lt;/i&gt;&lt;code&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%;font-size:10;" &gt;WHERE&lt;/span&gt;&lt;/i&gt;&lt;/code&gt;&lt;i style=""&gt; clause, even if you do not specify values for the other columns. (&lt;a href="http://dev.mysql.com/doc/refman/4.1/en/multiple-column-indexes.html"&gt;http://dev.mysql.com/doc/refman/4.1/en/multiple-column-indexes.html&lt;/a&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;It is clearly stated in the documentation that when second column is specified, MySQL will not use the index, or even if second column is used with first column with OR condition, it will not use the index. That’s why queries on &lt;i style=""&gt;indxtest3&lt;/i&gt; and &lt;i style=""&gt;indxtest4&lt;/i&gt; scanned all 10 records during search/select.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;Now what is the effect of indexing on locking? According to MySQL documentation:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.5in; text-align: justify;"&gt;&lt;i style=""&gt;A locking read, an &lt;a href="http://dev.mysql.com/doc/refman/4.1/en/update.html" title="12.2.10. UPDATE Syntax"&gt;&lt;code&gt;&lt;span style="line-height: 115%;font-size:10;color:blue;"  &gt;UPDATE&lt;/span&gt;&lt;/code&gt;&lt;/a&gt;, or a &lt;a href="http://dev.mysql.com/doc/refman/4.1/en/delete.html" title="12.2.1. DELETE Syntax"&gt;&lt;code&gt;&lt;span style="line-height: 115%;font-size:10;color:blue;"  &gt;DELETE&lt;/span&gt;&lt;/code&gt;&lt;/a&gt; generally set record locks on every index record that is scanned in the processing of the SQL statement. (&lt;a href="http://dev.mysql.com/doc/refman/4.1/en/innodb-locks-set.html"&gt;http://dev.mysql.com/doc/refman/4.1/en/innodb-locks-set.html&lt;/a&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;And what is record lock?&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.5in; text-align: justify;"&gt;&lt;i style=""&gt;Record lock: This is a lock on an index record. (&lt;a href="http://dev.mysql.com/doc/refman/4.1/en/innodb-record-level-locks.html"&gt;http://dev.mysql.com/doc/refman/4.1/en/innodb-record-level-locks.html&lt;/a&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;Few more points from MySQL documentation (&lt;a href="http://dev.mysql.com/doc/refman/4.1/en/innodb-locks-set.html"&gt;http://dev.mysql.com/doc/refman/4.1/en/innodb-locks-set.html&lt;/a&gt;):&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpFirst" style="margin-left: 0.75in; text-align: justify; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;1 -&lt;span style=";font-family:&amp;quot;;font-size:7;"  &gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;i style=""&gt;For &lt;/i&gt;&lt;code&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%;font-size:10;" &gt;SELECT ... FOR UPDATE&lt;/span&gt;&lt;/i&gt;&lt;/code&gt;&lt;i style=""&gt; or &lt;/i&gt;&lt;code&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%;font-size:10;" &gt;SELECT ... IN SHARE MODE&lt;/span&gt;&lt;/i&gt;&lt;/code&gt;&lt;i style=""&gt;, locks are acquired for scanned rows.&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="margin-left: 0.75in; text-align: justify; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;2 -&lt;span style=";font-family:&amp;quot;;font-size:7;"  &gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;code&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%;font-size:10;" &gt;SELECT ... FROM ... FOR UPDATE&lt;/span&gt;&lt;/i&gt;&lt;/code&gt;&lt;i style=""&gt; sets exclusive next-key locks on all index records the search encounters. &lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle" style="margin-left: 0.75in; text-align: justify; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;3 -&lt;span style=";font-family:&amp;quot;;font-size:7;"  &gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;code&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%;font-size:10;" &gt;UPDATE ... WHERE ...&lt;/span&gt;&lt;/i&gt;&lt;/code&gt;&lt;i style=""&gt; sets an exclusive next-key lock on every record the search encounters. &lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpLast" style="margin-left: 0.75in; text-align: justify; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;4 -&lt;span style=";font-family:&amp;quot;;font-size:7;"  &gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;code&gt;&lt;i style=""&gt;&lt;span style="line-height: 115%;font-size:10;" &gt;DELETE FROM ... WHERE ...&lt;/span&gt;&lt;/i&gt;&lt;/code&gt;&lt;i style=""&gt; sets an exclusive next-key lock on every record the search encounters. &lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;Conclusion&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;So, according to MySQL documentation, either we are explicitly locking records (first two points) or locks are implicit (last two points), locks will be acquired on records the search encounters. So if indexing is proper no locks will be acquired on rows on which we don’t want to. Even MySQL documentation says that:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.5in; text-align: justify;"&gt;&lt;i style=""&gt;It is important to create good indexes so that your queries do not unnecessarily need to scan many rows. (&lt;a href="http://dev.mysql.com/doc/refman/4.1/en/innodb-locks-set.html"&gt;http://dev.mysql.com/doc/refman/4.1/en/innodb-locks-set.html&lt;/a&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;Scanning many records will result in lock on those records due to which deadlocks can occur, performance can be degraded, or anything bad can happen.&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: justify;"&gt;If you are going to test the above scenario then you will also notice the performance differences between the queries if you have reasonable number of records in tables.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1572547582182708302-1295141618778678815?l=mjawaids.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://mjawaid.wordpress.com/2009/04/17/database-indexes-and-locks/' title='Database indexes and locks'/><link rel='replies' type='application/atom+xml' href='http://mjawaids.blogspot.com/feeds/1295141618778678815/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1572547582182708302&amp;postID=1295141618778678815' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/1295141618778678815'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/1295141618778678815'/><link rel='alternate' type='text/html' href='http://mjawaids.blogspot.com/2009/04/database-indexes-and-locks.html' title='Database indexes and locks'/><author><name>Jawaid</name><uri>http://www.blogger.com/profile/05875874113914026501</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1572547582182708302.post-8529601176228678512</id><published>2009-04-12T19:46:00.001+05:00</published><updated>2009-04-12T19:48:56.515+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='function calling'/><category scheme='http://www.blogger.com/atom/ns#' term='c/c++'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='perl'/><category scheme='http://www.blogger.com/atom/ns#' term='coding'/><title type='text'>Some coding tips!</title><content type='html'>&lt;p style="text-align: justify;"&gt;This article highlights some common pitfalls that are being made by developers. I’ll elaborate it with a simple example.&lt;/p&gt; &lt;p style="text-align: justify;"&gt;&lt;em&gt;$obj2-&gt;FuncOne( $obj1-&gt;GetData() );&lt;br /&gt;$obj2-&gt;FuncTwo( $obj1-&gt;GetData() );&lt;/em&gt; &lt;/p&gt; &lt;p style="text-align: justify;"&gt;The result of GetData is passed to FuncOne and FuncTwo in two subsequent calls. What is the benefit of this approach? Simple answer is to save memory, by not using any variable to save the result. This argument was very strong until there were memories with very less capacity. But now even home user has a system with memory in GBs. So this practice is not good in today’s world.&lt;/p&gt; &lt;p style="text-align: justify;"&gt;So, what’s the drawback of this approach? Performance degradation. But how can it degrades the performance? Let me explain a bit. Consider a situation where GetData runs a query on database to fetch some data from multiple tables by joining them. Joins thereselves are heavy by nature. So when GetData is called twice it will run query twice, and suppose that this code snippet is a part of a heavy process that can be called by multiple users on the web or in an enterprise application, just imagine what will happen to the database and application itself. The performance of the application will be degraded. Users of your application will get frustrated and at the end you will lose business.&lt;/p&gt; &lt;p style="text-align: justify;"&gt;Now let’s look at it from another perspective. This approach will also increase the CPU workload. When GetData will be called it will jump from one branch instruction to another and before that it has to save the current address to the stack so it can pop it back when it returns back to the caller function. This has to be done every time when function is called. And when function performs heavy computation it needs more memory and processing power, increasing the footprint of your application and execution time. So you’re wasting your servant’s (CPU) time and energy by assigning it the same task twice.&lt;/p&gt; &lt;p style="text-align: justify;"&gt;Other drawbacks can be that code is more error prone and is difficult to debug and troubleshoot, and code maintenance is high, especially when you have to modify the code to meet new requirements.&lt;/p&gt; &lt;p style="text-align: justify;"&gt;You can make your application and code much better and efficient by adhering to few simple best practices. In this case the rule is that&lt;/p&gt; &lt;p style="text-align: justify;"&gt;&lt;em&gt;“If result of a function is needed more than once then don’t call that function multiple times. Save the result of that function in a variable and use that variable instead. “&lt;/em&gt;&lt;/p&gt; &lt;p style="text-align: justify;"&gt;In view of this, above code could be written like this.&lt;/p&gt; &lt;p style="text-align: justify;"&gt;&lt;em&gt;my $result = $obj1-&gt;GetData();&lt;br /&gt;$obj2-&gt;FuncOne( $result );&lt;br /&gt;$obj2-&gt;FuncTwo( $result );&lt;/em&gt; &lt;/p&gt; &lt;p style="text-align: justify;"&gt;There is one extra line of code in above example but is more efficient and is much more readable than the previous one.&lt;/p&gt; &lt;p style="text-align: justify;"&gt;Let’s see another example.&lt;/p&gt; &lt;p style="text-align: justify;"&gt;&lt;em&gt;my $result = $obj1-&gt;GetData();&lt;br /&gt;$result = { %$result, %$someData };&lt;br /&gt;$obj2-&gt;FuncOne( $result );&lt;br /&gt;$obj2-&gt;FuncTwo( $obj1-&gt;GetData() );&lt;/em&gt; &lt;/p&gt; &lt;p style="text-align: justify;"&gt;In this example developer fetches the result, appends another previously got data to it and passes it to FuncOne. Then he needs the same result, so he called GetData one more time. Now again, we can write this code in much efficient manner.&lt;/p&gt; &lt;p style="text-align: justify;"&gt;&lt;em&gt;my $result = $obj1-&gt;GetData();&lt;br /&gt;my $result2 = $result;&lt;/em&gt; &lt;/p&gt; &lt;p style="text-align: justify;"&gt;&lt;em&gt;$result = { %$result, %$someData };&lt;/em&gt;&lt;/p&gt; &lt;p style="text-align: justify;"&gt;&lt;em&gt;$obj2-&gt;FuncOne( $result );&lt;br /&gt;$obj2-&gt;FuncTwo( $result2 );&lt;/em&gt; &lt;/p&gt; &lt;p style="text-align: justify;"&gt;&lt;em&gt; &lt;/em&gt;Here we have saved another call to GetData, which might be performing some heavy computation or running a heavy query with joining multiple tables in it.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1572547582182708302-8529601176228678512?l=mjawaids.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://mjawaid.wordpress.com/2009/01/26/some-coding-tips' title='Some coding tips!'/><link rel='replies' type='application/atom+xml' href='http://mjawaids.blogspot.com/feeds/8529601176228678512/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1572547582182708302&amp;postID=8529601176228678512' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/8529601176228678512'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/8529601176228678512'/><link rel='alternate' type='text/html' href='http://mjawaids.blogspot.com/2009/04/some-coding-tips.html' title='Some coding tips!'/><author><name>Jawaid</name><uri>http://www.blogger.com/profile/05875874113914026501</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1572547582182708302.post-4187313949657272317</id><published>2009-04-12T19:41:00.005+05:00</published><updated>2009-05-07T10:32:46.550+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='join table'/><category scheme='http://www.blogger.com/atom/ns#' term='entity relationship'/><category scheme='http://www.blogger.com/atom/ns#' term='database design'/><category scheme='http://www.blogger.com/atom/ns#' term='mapping table'/><category scheme='http://www.blogger.com/atom/ns#' term='junction table'/><category scheme='http://www.blogger.com/atom/ns#' term='link table'/><category scheme='http://www.blogger.com/atom/ns#' term='many-to-many relationship'/><category scheme='http://www.blogger.com/atom/ns#' term='db design'/><category scheme='http://www.blogger.com/atom/ns#' term='database'/><category scheme='http://www.blogger.com/atom/ns#' term='db'/><category scheme='http://www.blogger.com/atom/ns#' term='bridge table'/><title type='text'>Many-to-many relationship</title><content type='html'>&lt;em&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;“A &lt;strong&gt;junction table&lt;/strong&gt;, sometimes also known as a “Bridge Table”, “Join Table”, “Map Table”, or “Link Table”, is a table that contains common fields from two tables. It is on the many side of a one-to-many relationship with the other two tables. Junction tables are employed when dealing with many-to-many relationships in a database.”&lt;/span&gt;&lt;/em&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt; (&lt;a href="http://www.google.com/url?q=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FJunction_table&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFrqEzfre7QqTfisjzettxcqls_xjMTWjA"&gt;http://en.wikipedia.org/wiki/Junction_table&lt;/a&gt;)&lt;/span&gt; &lt;p class="MsoNormal" style="line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;As described in the definition, mapping tables are used when there is a many-to-many relationship between two tables. In this case, a third mapping table is used to map the relation between those two tables.&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;But I have seen this in one of my employer products where they were using mapping tables in lot of places. The most common and used was in financial application, where data was very crucial. I’ll explain this with an example for education domain. Let’s take classic example of students and classes. A student can be in only one class and in one class there can be multiple students. Therefore, the relationship between student and class is many-to-one. Or from other side relationship between class and student is one-to-many.&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;So, ideally we will have a table structure with two tables say, STUDENT and CLASS. CLASS will have a PK say CLASSNUM and fields for other class details. Similarly STUDENT will have a PK say STUDENTNUM and fields for other student details. One more field that STUDENT will have is FK to CLASSNUM field.&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;This is the most obvious design of the scenario. But in the above mentioned application this was not the case. We had a mapping table between STUDENT and CLASS. Yes! You have read it correctly. We had a STUDENTCLASSDETAILS table between STUDENT and CLASS, having a composite key of STUDENTNUM and CLASSNUM. But what is the reason for a mapping table here? What I have heard, (since I was not the designer of that DB at that time) that this mapping table has been introduced to improve performance and resolve locking issues. &lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;Well, let’s discuss how it can improve performance. Now consider the scenario where there are no relationships maintained in the database i.e. no referential integrity (Read my other blog on not having referential integrity - &lt;a href="http://mjawaid.wordpress.com/2009/04/02/2009/04/01/referential-integrity"&gt;http://mjawaid.wordpress.com/2009/04/01/referential-integrity&lt;/a&gt;). So there are no FKs in any table. Now we have a STUDENT with STUDENTNUM (PK), other fields, and CLASSNUM (note that it is not FK, and is not indexed either). CLASS has CLASSNUM (PK), and other fields. STUDENTCLASSDETAILS has STUDENTNUM and CLASSNUM as PK i.e. composite key and these are not FKs.&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;Now if two users are performing any operation on same record then first transaction locks some records in the STUDENT table then another transaction will not be able to read that students information. In this case the STUDENTCLASSDETAILS will allow us to read the information, at least student number and his class, since this information is most accessible. This way the second transaction will not wait for the other transaction resulting in improved performance and first transaction will acquire the lock successfully.&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;Now let’s see what are the problems with this approach?&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;First is the maintenance. When moving student from one class to another (when promoting to next level) two tables have to be updated, resulting in performance hit. Second, mapping table allows student to be inserted in multiple classes and we have witnessed this, resulting in loss of data integrity which is very crucial in financial applications and one can lost a big amount of money just due to silly mistakes. I’ll quote a statement from another forum here:&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;“&lt;/span&gt;&lt;span&gt;The designer of an application has a fiduciary responsibility to his employer/client and needs to ensure that data is as acurate as possible. To not enforce referential integrity is to tempt fate. &lt;span style="text-decoration: underline;"&gt;Employees get fired for building systems that contain bad data leading to bad business decisions. Consultants get sued.&lt;/span&gt;”&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt; &lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:8;color:#666666;"   &gt;Pasted from &lt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;"  &gt;&lt;a href="http://www.google.com/url?q=http%3A%2F%2Fwww.access-programmers.co.uk%2Fforums%2Farchive%2Findex.php%2Ft-33531.html&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFrqEzfpgwZwRcvB_7VkuH5EO90nZ1DXgw"&gt;&lt;span style=";font-family:&amp;quot;;font-size:8;"  &gt;http://www.access-programmers.co.uk/forums/archive/index.php/t-33531.html&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:8;color:#666666;"   &gt;&gt; &lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="line-height: 115%;font-family:&amp;quot;;font-size:12;"  &gt;&lt;br /&gt;Although the person made a comment on not having referential integrity but the underlined statement has the crux of the topic. So the conclusion is when designing an application or database, also consider other scenarios and pros and cons of the approach being adopted, not only one scenario. In other words if one approach is solving your problem then also consider what other problems we can face due to it, and prepare for those as well.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1572547582182708302-4187313949657272317?l=mjawaids.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://mjawaid.wordpress.com/2009/04/02/many-to-many-relationship/' title='Many-to-many relationship'/><link rel='replies' type='application/atom+xml' href='http://mjawaids.blogspot.com/feeds/4187313949657272317/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1572547582182708302&amp;postID=4187313949657272317' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/4187313949657272317'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/4187313949657272317'/><link rel='alternate' type='text/html' href='http://mjawaids.blogspot.com/2009/04/mapping-tables.html' title='Many-to-many relationship'/><author><name>Jawaid</name><uri>http://www.blogger.com/profile/05875874113914026501</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1572547582182708302.post-8886930903587170272</id><published>2009-04-12T19:32:00.003+05:00</published><updated>2009-04-14T10:25:10.185+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='database design'/><category scheme='http://www.blogger.com/atom/ns#' term='db design'/><category scheme='http://www.blogger.com/atom/ns#' term='referential integrity'/><category scheme='http://www.blogger.com/atom/ns#' term='database'/><category scheme='http://www.blogger.com/atom/ns#' term='db'/><title type='text'>Referential Integrity</title><content type='html'>&lt;p class="MsoNormal"&gt;When I first looked at the database of an application for one of my employers, I was bit surprised with the database design that was made by previous software engineers/analysts. Two things that most surprised me were no integrity constraints and mapping tables between tables having one-to-many relationship. I’ll focus on the first one here but second one will also be part of it because it is also related to data integrity. The reason I got for not using integrity constraints was performance. Before commenting on it and going further into the details let me quote from few resources about not having integrity constraints.&lt;/p&gt; &lt;p style="margin: 0pt 0pt 0.0001pt;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:11;"  &gt;“Q) When not to use referential integrity?&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0pt 0pt 0.0001pt;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:11;"  &gt;Ans) The short answer is Never. The designer of an application has a fiduciary responsibility to his employer/client and needs to ensure that data is as acurate as possible. To not enforce referential integrity is to tempt fate. Employees get fired for building systems that contain bad data leading to bad business decisions. Consultants get sued.”&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0pt 0pt 0.0001pt;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:11;"  &gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0pt 0pt 0.0001pt;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:8;color:#666666;"   &gt;Taken from &lt;/span&gt;&lt;a href="http://www.access-programmers.co.uk/forums/archive/index.php/t-33531.html"&gt;&lt;span style=";font-family:&amp;quot;;font-size:8;"  &gt;http://www.access-programmers.co.uk/forums/archive/index.php/t-33531.html&lt;/span&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt; &lt;/p&gt;&lt;p style="margin: 0pt 0pt 0.0001pt;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:11;"  &gt;“So if these rules are being examined for each and every database transaction, what is that doing to my system performance and response time? The answer is that it depends. Several things such as the volume of transactions and the types of constraints defined will affect performance. If you define cascading deletes across nine related tables, you are going to see a lag in response time while the database determines how many rows must be deleted from each table. This will also multiply the performance hit of other database features, such as journaling. So keep in mind that, yes, there is a cost for referential integrity in terms of system performance.&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:11;"  &gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0pt 0pt 0.0001pt;"&gt;&lt;span style="text-decoration: underline;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:11;"  &gt;On the other hand, you might experience an improvement in performance, since the rules and relationships are enforced at the system level in the database. Instructions executed at this level run more efficiently than similar logic placed in a high-level language.&lt;/span&gt;&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:11;"  &gt; Just as you would weigh the pros and cons of creating additional indices over your database, you should also consider the factors associated with adding referential integrity.&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:11;"  &gt; “&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0pt 0pt 0.0001pt;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:11;"  &gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0pt 0pt 0.0001pt;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:8;color:#666666;"   &gt;Taken from &lt;/span&gt;&lt;a href="http://www.itjungle.com/mpo/mpo101002-story03.html"&gt;&lt;span style=";font-family:&amp;quot;;font-size:8;"  &gt;http://www.itjungle.com/mpo/mpo101002-story03.html&lt;/span&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt; &lt;/p&gt;&lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;strong&gt;&lt;span style=";font-family:&amp;quot;;font-size:12;color:#330099;"   &gt;“&lt;/span&gt;&lt;/strong&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;color:#330099;"   &gt;Why Disable Constraints?&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span&gt;During day-to-day operations, constraints should always be enabled. In certain situations, temporarily disabling the integrity constraints of a table makes sense for performance reasons. For example:&lt;/span&gt;&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=";font-family:Symbol;font-size:10;"  &gt;&lt;span&gt;&lt;span style="font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;font-family:&amp;quot;;font-size:7;"  &gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span&gt;When loading large amounts of data into a table using SQL*Loader&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=";font-family:Symbol;font-size:10;"  &gt;&lt;span&gt;&lt;span style="font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;font-family:&amp;quot;;font-size:7;"  &gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span&gt;When performing batch operations that make massive changes to a table (such as changing each employee number by adding 1000 to the existing number)&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=";font-family:Symbol;font-size:10;"  &gt;&lt;span&gt;&lt;span style="font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;font-family:&amp;quot;;font-size:7;"  &gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span&gt;When importing or exporting one table at a time&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style="text-decoration: underline;"&gt;&lt;span&gt;Temporarily&lt;/span&gt;&lt;/span&gt;&lt;span&gt; turning off integrity constraints can speed up these operations.”&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span&gt; &lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;&lt;span style=";font-family:&amp;quot;;font-size:8;color:#666666;"   &gt;Taken from &lt;/span&gt;&lt;a href="http://download.oracle.com/docs/cd/B14117_01/appdev.101/b10795/adfns_co.htm"&gt;&lt;span style=";font-family:&amp;quot;;font-size:8;"  &gt;http://download.oracle.com/docs/cd/B14117_01/appdev.101/b10795/adfns_co.htm&lt;/span&gt;&lt;/a&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt; &lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="text-decoration: underline;"&gt;And the most important one:&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;a href="http://rapidapplicationdevelopment.blogspot.com/2007/07/referential-integrity-data-modeling.html"&gt;http://rapidapplicationdevelopment.blogspot.com/2007/07/referential-integrity-data-modeling.html&lt;/a&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;The whole article is worth reading. It explains data modeling mistakes and the number one is not having referential integrity. I’ll quote its conclusion here:&lt;/p&gt; &lt;p&gt;“&lt;span&gt;Conclusion&lt;/span&gt;&lt;/p&gt; &lt;p&gt;Well, hopefully I’ve convinced you to avoid the urge to be a lazy data modeler, design for the future, use a data modeling tool, and drop constraints during bulk load operations. In short, always use referential integrity. But if not, hopefully &lt;span style="text-decoration: underline;"&gt;you’ll at least understand when people curse your name several years from now&lt;/span&gt;. &lt;img src="http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /&gt; ”&lt;/p&gt; &lt;p class="MsoNormal"&gt;Well, these give you a fine idea whether one should use referential integrity constraints (RIC) or not. Even if it is a performance reason, one should use RIC since ultimately data integrity has to be checked either at application level or system level and as said above instructions executed at system level are much faster and efficient. And, if there is no data integrity check then your data is at risk, as in the above mentioned case where on production system, a record in one table was mapped to multiple due to mapping table and no integrity constraints. We had several issues on production system due to this including deadlocks and the one just mentioned. There are several bugs posted on the bugzilla for that project which are examples of this.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1572547582182708302-8886930903587170272?l=mjawaids.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://mjawaid.wordpress.com/2009/04/01/referential-integrity/' title='Referential Integrity'/><link rel='replies' type='application/atom+xml' href='http://mjawaids.blogspot.com/feeds/8886930903587170272/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1572547582182708302&amp;postID=8886930903587170272' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/8886930903587170272'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1572547582182708302/posts/default/8886930903587170272'/><link rel='alternate' type='text/html' href='http://mjawaids.blogspot.com/2009/04/referential-integrity.html' title='Referential Integrity'/><author><name>Jawaid</name><uri>http://www.blogger.com/profile/05875874113914026501</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
