Hi!

I find the following query in my slow query log:

SELECT n.* FROM node n LEFT JOIN xmlsitemap_node xn ON xn.nid = n.nid WHERE xn.nid IS NULL AND n.status <> 0 LIMIT 0, 100

I'm not an SQL expert, so I don't know what is the problem with this query, but I attached the explain of this query. I think the main problem with this query, it doesn't use key for select in node table. This query was logged for every database which use the xmlsitemap module, no matter how many nodes in the node table.

Comments

dave reid’s picture

Status: Active » Postponed (maintainer needs more info)

Could you try the same query with WHERE ... n.status = 1 instead of n.status <> 0?

xmarket’s picture

Hi!

Here is the explain of the modified query.

Anonymous’s picture

Why isn't the engine using the node_status_type index it identified? It is doing a full table scan why? What version of MySQL are you using?

xmarket’s picture

MySQL 5.0.83 with Percona patchset 5.0.83-b17. It's a gentoo package.

I really don't know the reason why. :S

I've got the same result with the latest gentoo package MySQL 5.0.84 with Percona patchset 5.0.84-b18 and the custom built MySQL 5.1.38 without Percona patchset.

xmarket’s picture

Hi!

I gave a chance to the latest MySQL release. Unfortunately the explain result remained the same with MySQL 5.0.86 too.

Anonymous’s picture

@xmarket: Can you run this through the MySQL support venues? We really need to know why the index is being ignored and how to change the query.

dave reid’s picture

Status: Postponed (maintainer needs more info) » Postponed
Issue tags: +Needs database review

I don't think this query is ignore the index on the {node} table. In fact the query log shows that it's only using a WHERE and not a FILESORT, so that's the best it can get there. The part about "Using index; Not exists" is just fine because it's using the proper index on {xmlsitemap_node} and the query is a not exists type of query. I really don't see how this could be optimized further.

Similar query in 6.x-2.x returns the same type of result:
SELECT n.nid FROM node n LEFT JOIN xmlsitemap x ON x.type = 'node' AND n.nid = x.id WHERE x.id IS NULL ORDER BY n.changed DESC

This should be postponed unless a MySQL and/or PostgreSQL guru can review this.

dave reid’s picture

Status: Postponed » Closed (works as designed)

I can't see what else we can do here to help, so marking as by design.