I have a sql table of 5,000,000 entries with 5 columns over which I need to make a 4-condition (TEXT type) select. The table has columns id, name, street, city, zip and my select looks like this
SELECT id FROM register WHERE name=%s AND zip=%s AND city=%s AND street=%s
Problem is, i need to speed up this query, because i need to do 80 000 of this queries and now it takes half a day.
答案 0 :(得分:0)
%s
占位符表示您的所有四列都是varchar或text。如果是这样,那么以下索引可能会有所帮助:
CREATE INDEX idx ON register (name, zip, city, street, id)
索引的前四部分覆盖WHERE
子句,第五部分覆盖id
子句所需的SELECT
列。