-2
How can I make faster queries to a table MySQL
with 3 million records, the table has only 4 columns, and it takes me almost 5 seconds to return data. The fields I search have index
. To Query
returns close to 50,000 records and is executed by MySQL WorkBench
. I leave some more information below and if necessary I can provide more information.
Query:
SELECT campo2, campo3, campo4 FROM tabela2
WHERE campo2=25 AND campo3>='2016-09-01 00:00' AND campo3<='2016-10-01 00:00'
Structure Table 2:
id - bigint
campo2 - int - index
campo3 - timestamp - index
campo4 - float
Can someone help me with something?
It is difficult to answer without you posting more information like the template of the tables involved and query that is slow.
– Ricardo Pontual
Friend, I believe that you can improve considerably the execution time of the query by changing the way of comparing the dates by the BETWEEN command. It would be interesting to post the model of the bank so that we can analyze the problem better.
– Geovane da Silva de Jesus
@Gokussjgod and tinkering with my.ini might solve something?
– Tmc
Right. Do you need to bring all the fields in the table even? (SELECT * FROM table2...)
– Geovane da Silva de Jesus
@Geovanedasilvadejesus no, I can leave the id
– Tmc
Please avoid long discussions in the comments; your talk was moved to the chat
– Maniero