{"id":621,"date":"2014-11-20T15:42:12","date_gmt":"2014-11-20T15:42:12","guid":{"rendered":"http:\/\/vickistan.com\/?p=621"},"modified":"2015-12-03T15:23:03","modified_gmt":"2015-12-03T15:23:03","slug":"mysql-indexing-stuff","status":"publish","type":"post","link":"https:\/\/vickistan.com\/?p=621","title":{"rendered":"MySQL Indexing Stuff"},"content":{"rendered":"<p><strong>#Determine whether a table is indexed<\/strong><br \/>\nshow index from [table name]<\/p>\n<p><strong>#Display a table&#8217;s index<\/strong><br \/>\nmysql&gt; show index from mysql.user;<br \/>\n+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |<br \/>\n+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n| user | 0 | PRIMARY | 1 | Host | A | NULL | NULL | NULL | | BTREE | | |<br \/>\n| user | 0 | PRIMARY | 2 | User | A | 6 | NULL | NULL | | BTREE | | |<br \/>\n+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n2 rows in set (0.01 sec)<\/p>\n<p><strong>#Add an index to a table<\/strong><br \/>\nTurn on the slow log, and look for a slow query to index. Use the Describe command.<\/p>\n<pre lang=\"LANGUAGE\">DESCRIBE\r\n\r\n* It will tell you how many rows it had to examine and what method it used for matching. \r\n* Using the where method, mysql will scan the entire table to find a match, pulling up each row and \r\n* checking to see if the columns match its criteria.\r\n* This is SLOW\r\n\r\n<strong>To actually create the index<\/strong>\r\n* Use CREATE INDEX to create an index on the table as follows:<\/pre>\n<pre lang=\"LANGUAGE\">CREATE INDEX &lt;index_name&gt; on &lt;tbl_name&gt; (&lt;column_name&gt;)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#Determine whether a table is indexed show index from [table name] #Display a table&#8217;s index mysql&gt; show index from mysql.user; +&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | &hellip; <a href=\"https:\/\/vickistan.com\/?p=621\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,8],"tags":[],"class_list":["post-621","post","type-post","status-publish","format-standard","hentry","category-linux","category-mysql"],"_links":{"self":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts\/621","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=621"}],"version-history":[{"count":7,"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts\/621\/revisions"}],"predecessor-version":[{"id":629,"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts\/621\/revisions\/629"}],"wp:attachment":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}