Welcome our webmaster and SEO forum
Please enjoy the forum, contribute what you can, and wind up the Moderators!
Closed Thread
Results 1 to 3 of 3

Thread: Creating Indexes

  1. #1
    gilbertsavier is offline Member gilbertsavier is on a distinguished road
    Join Date
    Jun 2009
    Posts
    31

    Default Creating Indexes

    Hi,

    Database indexes help to speed the retrieval of data from MySQL database server faster. When retrieving the data, MySQL first check whether the indexes exists; If yes it will use index to select exact physical corresponding rows without scanning the whole table.

    In general, it is suggested that you should put indexes on columns you usually use in retrieval such as primary key columns and columns used in join and sorts. Why not index every column? The most significant is that building and maintaining an indexes tables take time and storage space on database.

    Usually you create indexes when creating tables. Any column in creating table statement declared as PRIMARY KEY, KEY, UNIQUE or INDEX will be indexed by MySQL. In addition, you can add indexes to the tables which has data. The statement to create index in MySQL as follows:

    CREATE [UNIQUE|FULLTEXT|SPATIAL] INDEX index_name
    USING [BTREE | HASH | RTREE]
    ON table_name (column_name [(length)] [ASC | DESC],...)

    First you specify the index based on the table types or storage engine:

    * UNIQUE means MySQL will create a constraint that all values in the index must be distinct. Duplicated NULL is allowed in all storage engine except BDB.
    * FULLTEXT index is supported only by MyISAM storage engine and only accepted columns which have data type is CHAR,VARCHAR or TEXT.
    * SPATIAL index supports spatial column and available in MyISAM storage engine. In addition, the column value must not be NULL.

    Then you name the index using index types such as BTREE, HASH or RTREE also based on storage engine. Here are the list:
    Storage Engine Allowable Index Types
    MyISAM BTREE, RTREE
    InnoDB BTREE
    MEMORY/HEAP HASH, BTREE
    NDB HASH


    Finally you declare which column on which table using the index.

    In our sample database you can add index to officeCode column on employees table to make the join operation with office table faster as follows:

    CREATE INDEX officeCode ON employees(officeCode)

    Thanks & regards,
    Lokananth

  2. #2
    surreypcsupport's Avatar
    surreypcsupport is offline Senior Member surreypcsupport is on a distinguished road
    Join Date
    Nov 2008
    Location
    surrey
    Posts
    569

    Default

    I generally try and join using the primary key which is usually a clustered index. This is the fastest type of join because clustered indexes only exist on columns where there are no duplicates.

    Non-clustered index I use less. The only time you should use one is if you commonly join on a column that is not the primary key and there are large numbers of rows i.e hundreds of thousands in the table. That is the only time you will benefit from the faster querying because of the overhead used to create and maintain indexes.

    In my experience most people over use non-clustered indexes.

  3. #3
    alex28's Avatar
    alex28 is offline Junior Member alex28 is on a distinguished road
    Join Date
    Jun 2010
    Posts
    6

    Default

    thanks for this great information it is help full to me to know more about the indexes

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124