• cogmios

    (@cogmios)


    Isn’t it strange to place the field “count” in the wp_terms_taxonomy table?

    If an existing term is added then it would simply be a matter of updating wp_term_reletionships with the post id and the term_taxonomy_id.

    Now the wp_terms_taxonomy table needs explicitly be updated with a count++.

    Wouldn’t you do this normally outside a SQL table?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Kafkaesqui

    (@kafkaesqui)

    Well, consider at one time there was no such count column (and going back a bit, there really wasn’t). What would lead the developers to decide to add one?

    Thread Starter cogmios

    (@cogmios)

    That’s exactly my question, and if I do a Google Search on it , there seem to be quite a lot of people with the same question.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    The count of a term use is something that is pulled a lot, mainly when building a tag cloud. When pulling tags and counts of those tags use, the query can take some time (it would involve a couple more joins I think, as well as the count(*) operator and a group by). Keeping an up-to-date count is no big deal, really (the only time it happens is adding or modifying a post), and it’s faster to pull this data from the table than to have the database do calculation and all the various work required for it to do that.

    At least, that’s the argument in favor of it. I don’t necessarily agree with it, but it does make some sense. The data is pulled out and used a heck of a lot more often than it is modified. So, you optimize for the pulling of the data.

    In other words, WordPress developers tend to look at the things that happen when the page is displayed and try to optimize for that case. Avoid having the DB do any calculation, avoid overly complex joins, etc. This is why adding posts and such have high overhead, because those cases don’t happen anywhere near as often as the page actually being displayed.

    Kafkaesqui

    (@kafkaesqui)

    What Otto said. ;)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘field COUNT in wp_terms_taxonomy table’ is closed to new replies.