Support » Plugin: Posts 2 Posts » [Plugin: Posts 2 Posts] Use of compound indexes

  • 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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author scribu


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

    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 😉

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Posts 2 Posts] Use of compound indexes’ is closed to new replies.