Forum Moderators: open

Message Too Old, No Replies

"Size" field for an index

         

csdude55

5:20 pm on Mar 19, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm not sure that I understand the thought behind changing the size of an index column.

For example, I have a column that's variable character size (15) (sorry, if I say the actual type then I still get a Forbidden error on here), but the possibilities are all unique after the first 6 characters. Does this mean that I should set the index to "column(6)"?

I thought that this would just save the first 6 characters; eg:

// this is what I thought the index "column" would look like
csdude55
brotherhood
nickmns
not2easy
phranque

// this is what I thought the index "column(6) would look like
csdude
brothe
nickmn
not2ea
phranq

So if that was correct then "column(6)" would logically be smaller and faster.

But I did a test, creating an index for "column" and another for "column(6)". I used EXPLAIN to run a select query on a value that was 12 characters long, and the selected index was "column(6)". Then I did another query on a value that was 6 characters long, and the selected index was "column" (without the size limit).

So I guess that my logic is wrong, and that it's not always faster?

csdude55

7:35 pm on Mar 19, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That's in MySQL... sorry, I forgot to specify

coopster

7:26 pm on Mar 23, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I believe you are referring to prefix indexes, which are not always faster, but that also depends on the amount of stored data, the WHERE clause, etc. You could receive ERROR 1071 max key length issue when trying to create an index on a variable character column that extends the limitations and that is when a prefix index may be your resolution. Here is the doc page on MySQL:
[dev.mysql.com...]