In a web based java application, I have a table with this schema
Column Datatype
Userid char(25) primary key;
name char(100)
address varchar(120)
email char(50) UNIQUE;
with 120000 records. (Cardinality)
Now, I want to fetch the matching names (character by character) stored under column -> name. when I start typing in a search box (through ajax obviously).
e.g. if I write p then all names starting from letter p will be retrieved and would come in the list to populate.
Right now I am not using any indexing
. So how could I use it to make the access/search faster.
The database I am using is MySql 5 and java as frontend.
Any suggestion for using appropriate collection for this purpose or any hashing would help in the database if yes please elaborate.
Though I have got the right track for this StackOverflowers. If I
modify the question and use hashing in place of indexing with all its
definition and usage statistics then how to do that and is it
beneficial?
The simplest way is just:
And also, as names are variable length, use VARCHAR instead. For your key, use INT!
You can shrink your index to one byte if you search by one character only:
Then, for better performance, you can use covering index. It means you need to have all required data indexed properly so it resides in memory (make sure you configured your server properly) and MySQL does not need to read from disk.