Optimize WP_Query

Optimize WP_Query

Every time you run query_posts() or create a new WP_Query() (secondary loop), four queries are run:

  1. Getting the posts according to your query string
  2. Calculating how many posts exist for this query (to create pagination)
  3. Loading all metadata for the posts
  4. Loading all taxonomy term information for the posts
  5. It is possible to turn off queries 2-4 to increase performance, like this:

XX

$my_query = new WP_Query(array(
    'no_found_rows' => true,
    'update_post_meta_cache' => false,
    'update_post_term_cache' => false
));

Andrew Nacin: WP_Query / WordPress In-depth - summary and highlights - Useful Snippets


Dodavanje indexa na tabele kako bi se ubrzao rad sa tabelama u bazi

Nije mi samo jasno zašto u originalu, u core WP, ovo nije dodato? Ne razumem koje su loše posledice?

Članak koji do detalja objašnjava šta ovaj prvi plugin menja i zašto: Adding high-performance keys to MySQL tables to speed up WordPress and Speeding up WordPress database operations

More articles:


WordPress database index fixer by ManagedWPHosting.nl – Add indexes, keys, primary keys again to your WordPress database tables

Mislim da je ovo slično: hubbardlabs/foreign-keys-pro: A WordPress plugin to add foreign keys.


Ako imaš errors: Add PRIMARY KEY and UNIQUE KEY to WordPress core database tables - wpXSS


Optimize Wordpress DB

WordPress wp_options table autoload micro-optimization - Sysadmins of the North

Add index to

ALTER TABLE wp_options ADD INDEX (`autoload`);

Add MySQL Indexes for WordPress Sites #24044 (Add index to wp_options to aid/improve performance) – WordPress Trac performance - Slow Query for the wp_options table - WordPress Development Stack Exchange

Convert MySQL MyISAM tables to InnoDB

Foreign Keys Pro


Replacing the Database Class, Which Contains Built-in Database Functions, for Performance Reasons

HyperDB by Automattic is currently the only active project in this space. It has interesting options such as different tables on different databases or hosts, replication aka read and write servers, failover for downed hosts, and more. Most of these options are designed for large deployments, as this plugin is developed for the needs of the WordPress.com hosting platform.

Next Level Cache intercepts queries and selectively caches them. It is an only database replacement plugin that speeds up execution, and it is still maintained. Installed as a “drop-in” it overrides the class that controls access to the database. Pluging store cached data in the wp_options table and that is loaded upfront with one large query instead of many small ones. Although idea was nice it is abandoned long.

Advanced: Replication and partitioning

Sharding.

SharDB je definitivno davno napušten, ali tu je archive repo rrennick/shardb: SharDB multi database plugin for WordPress

Multi-DB plugin with repo at wpmudev/multi-db: Allows you to partition your large WordPress Multisite database across multiple servers for scalability.


Use WP_ALLOW_REPAIR to Repair the WordPress Database

Fix A Corrupted WordPress Database To fix the database connection error, you should log into your FTP client and go to the root WordPress folder. Then, edit the wp-config file there, by adding the following code and saving your file.

define("WP_ALLOW_REPAIR", true);

Once done, go to /wp-admin/maint/repair.php

How To Repair the WordPress Database via WP-CLI

If you’re using the command line to access your WordPress installation, you can use WP-CLI to repair the database.

To do this, use the wp db repair command. This can be the quickest way to repair the database.


Pazi ovo je super: as Plugin: ServerPress/databasecollationfix: Database Collation Fix tool ServerPress/random-db-prefix: Provides a random database prefix for new sites


This is important! - update_post_term_cache speed up wp_query WOOW: https://thomasgriffin.io/optimize-wordpress-queries/ ?? https://docs.google.com/presentation/d/1OXVFo1TSiz2jgIytsiUrLvBUiZztMl8FmYVIbUd_YdE/edit?pli=1#slide=id.g882f3d3_0_84 http://www.smashingmagazine.com/2012/06/diy-caching-methods-wordpress/


Možemo koristiti osnovne WP CLI komande:

wp db optimize

How to Clean up Your wp_options Table and Autoloaded Data


Cleaning up with WP-CLI: Cleaning a Large WordPress Database

date 26. Jun 2016 | modified 29. Dec 2023
filename: Wordpress » Performance » Optimize SQL Database and WP_Query