WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
Use of compound indexes (3 posts)

  1. Jason Judge
    Member
    Posted 1 year ago #

    Just looking at the tables that p2p installs (p2p and p2p_meta) they contain a number of indexes, each on single columns. Note that a query can [generally] only use one index on a table, so some compound indexes may give better results.

    Both tables have indexes on the meta_key and p2p_type columns, which has a very low cardinality compared to the id fields (p2p_id, p2p_to and p2p_from). That low cardinality makes those indexes pretty useless, and if MySQL chooses to use the index on meta_key, it could slow things down a lot as a website scales.

    If the id fields are only ever used in queries with the other indexed columns in the WHERE-clause, then it is likely to give you better results if they are merged into compound indexes.

    I've not got any stats yet, or tried any of this merging (I'm still importing a massive site) but when I do, I'll come back to this post. In the meantime, those are my thoughts on just a casual glance, and with too many years of RDBMS experience tucked away.

    http://wordpress.org/extend/plugins/posts-to-posts/

  2. scribu
    Member
    Plugin Author

    Posted 1 year ago #

    Didn't think of composite indexes. I'd be very interested in whatever stats you can share.

  3. Jason Judge
    Member
    Posted 1 year ago #

    I've changed our indexes to compound indexes, but cannot see any real difference. Since we have relatively few (i.e. two) connection types, there is not much narrowing-down the compound index can do.

    On the other hand, it did not slow things down, and the p2p_type index on its own will never be of any use, and will never be used anyway, assuming the database optimiser gets things right. I would personally add it in as the first column on compound indexes for both the "to" and "from" links. That would make the assumption that rows are never selected on "to" or "from" without also having a "p2p_type" in the selection for context. If that assumption is incorrect, then there is no harm leaving it as it is.

    Oh well - no real advice there: do it, or don't do it ;-)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.