I need to select 25 columns from a database, with a conditions WHERE and ORDER BY.
I tried to make an index for that but it is limited to 16 columns only. How could I organize the mysql statements and database for the fastest way to select these 25 columns from the database within PHP?
Example Table:
Columns: A, B, C, D, E, F, ….
Query: “SELECT A, B, C, D, E, F, … FROM table WHERE X = 5 ORDER BY Z”
UPDATE 1:
It is a large table (many rows) that’s why I need an index to speed up the process.
Indexes do not have a performance inpact in relation to the number of columns you select (excluding FULLTEXT). They are only used to speed when you use selection (WHERE) and sometimes ordering (ORDER BY) and agregation (GROUP BY etc.).
In this case you will need to define indexes on X and Z for optimal efficiency. Because MySQL can only use 1 index per query you’ll need an index on (X,Z) (because selection on X is first, then ordering on Z). Note that this doubles as an index for X.
Also, an index containing all columns is almost the same as a table entry (albeit sorted) so you won’t get much SELECT performance improvement from it, while INSERT/UPDATE/DELETE performance would plummet.