I have question about database optimizing, indexing. I have table that called “projects” and i will execute queries like this:
Ordering Queries
SELECT * FROM projects WHERE active = 1 ORDER BY created
SELECT * FROM projects WHERE active = 1 ORDER BY project_deadtime
SELECT * FROM projects WHERE active = 1 ORDER BY project_allowedtime
My Table Stucture Like This
id int(11) NO PRI NULL auto_increment
employer_id int(11) NO MUL NULL
project_title varchar(100) NO MUL NULL
project_description text NO NULL
project_budget int(11) NO NULL
project_allowedtime int(11) NO NULL
project_deadtime date NO NULL
created datetime NO MUL NULL
active tinyint(1) NO MUL NULL
Which columns should i create index and how(single or multiple column index ?). For example should i use active-created & active-project_deadtime & active-project_allowedtime multiple indexes or single active index is enough ? Thanks
EDIT: projects table will have maximum 1000-2000 rows. SELECT queries performance is important and about %90 of projects is active.
Which queries will be used most often? How many rows will there be? Which queries need to be fastest? Do you run more
SELECTs or moreINSERTs? There are a lot of considerations in tuning performance of a database.Based only on what you’ve posted, you’re using the following columns only:
An index solely on
activewould do little good — it would probably narrow the results down to about half.The other columns are each potential indices. If you’re not as concerned with the performance of
INSERTs as the performance ofSELECTs, I’d say index all three, giving priority to the column likely to narrow down a query to the fewest rows:This will allow MySQL to use the index if only the first column is used (e.g., if only
createdis needed) or if both columns are used (to narrow results even further).