Optimize query selection from a table using millionth rows

I am developing a self-service Wordpress Wordpress website.

On one of the pages, I launched a function that executes a query to the wordpress database to check that the message has already been published or not, I compare the header to check it.

Here is my request:

$wpdb->get_row("SELECT id FROM wp_posts WHERE post_title = '" . $title . "'", 'ARRAY_A');

So, I check if the $ header has been published or not, but I'm afraid if the number of messages grows, let it say 1 million messages, I am afraid that it will be very slow.

Any suggestion on how to make this query faster? I heard about CREATE INDEX and mysql caching, but I don’t understand how to implement it .. any explanations and recommendations on the links would be much appreciated.

+3
source share
4 answers

:

CREATE INDEX IX_wp_posts_post_title ON wp_posts (post_title)

, .

+1

, , , post_title.

, - , SQL-Select , , SQL-Injection .

+1

, . , .

, sql-. .

.

myindex mytable ( );

This will help you choose ... but if you really have millions of rows, you might be better off getting some database recommendations - you might need to break up your data.

0
source

If you are checking to see if there is any particular record in your database, you should use the message identifier to check instead of the name. One of them is a guaranteed unique identifier (provided that it is a primary key) and two, because the request will look for it much faster.

0
source

Source: https://habr.com/ru/post/1785535/


All Articles