Giter Club home page Giter Club logo

fast-wp-query's Introduction

#Fast WP_Query WP_Query MySQL optimization by using object cache

##Benchmark ###1. Select last 10 posts (7000 rows in db)

$query = new WP_Query( [ 'post_type' => 'post', 'posts_per_page' => 10 ] );

####Default SQL:

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.post_date DESC LIMIT 0, 10;

Query time: 31.588 ms

####With plugin SQL:

SELECT wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.post_date DESC LIMIT 0, 10;

Query time: 7.869 ms

###2. Select random 10 posts (7000 rows in db)

$query = new WP_Query( [ 'post_type' => 'post', 'orderby' => 'rand', 'posts_per_page' => 10 ] );

####Default SQL:

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_6_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') ORDER BY RAND() LIMIT 0, 10;
SELECT FOUND_ROWS();
SELECT wp_6_posts.* FROM wp_posts WHERE ID IN (9424,4699,834,9064,10472,284,9078,8091,2062);

Query time: 33.383 ms

####With plugin SQL:

SELECT wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.ID IN (10337,10336,9863,9814,10433,10414,9906,9989,9664,9599) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') ORDER BY FIELD( wp_posts.ID, 10337,10336,9863,9814,10433,10414,9906,9989,9664,9599 ) LIMIT 0, 10;
SELECT wp_posts.* FROM wp_posts WHERE ID IN (9863,9814,10433,10414,9906,9989,9664,9599);

Query time: 10.413 ms

fast-wp-query's People

Watchers

James Cloos avatar Alex Osmichenko avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.