Comment 13 for bug 965333

Revision history for this message
Vish Ishaya (vishvananda) wrote :

So the issue here was the old code was doing joins without relationships set in the model (due to us removing foreign keys, leading to a cartesian product)

OLD SQL:

SELECT fixed_ips.created_at AS fixed_ips_created_at, fixed_ips.updated_at AS fixed_ips_updated_at, fixed_ips.deleted_at AS fixed_ips_deleted_at, fixed_ips.deleted AS fixed_ips_deleted, fixed_ips.id AS fixed_ips_id, fixed_ips.address AS fixed_ips_address, fixed_ips.network_id AS fixed_ips_network_id, fixed_ips.virtual_interface_id AS fixed_ips_virtual_interface_id, fixed_ips.instance_id AS fixed_ips_instance_id, fixed_ips.allocated AS fixed_ips_allocated, fixed_ips.leased AS fixed_ips_leased, fixed_ips.reserved AS fixed_ips_reserved, fixed_ips.host AS fixed_ips_host
FROM fixed_ips, instances, networks
WHERE fixed_ips.updated_at < ? AND fixed_ips.instance_id IS NOT NULL AND fixed_ips.allocated = ? AND (instances.host = ? AND networks.multi_host = ? OR networks.host = ?)

(Note the lack of ON clauses in the joins)

SQL after the above patch:

SELECT fixed_ips.id AS fixed_ips_id
FROM fixed_ips JOIN networks ON networks.id = fixed_ips.network_id JOIN instances ON instances.id = fixed_ips.instance_id
WHERE fixed_ips.deleted = ? AND fixed_ips.allocated = ? AND fixed_ips.updated_at < ? AND (instances.host = ? AND networks.multi_host = ? OR networks.host = ?)