diff options
author | Vishvananda Ishaya <vishvananda@yahoo.com> | 2010-09-12 18:25:15 -0700 |
---|---|---|
committer | Vishvananda Ishaya <vishvananda@yahoo.com> | 2010-09-12 18:25:15 -0700 |
commit | dbb3358f851c245ccb5ea9a9c7ace636b4e73a80 (patch) | |
tree | 5e1e63d9cbedb72e3a113d65caa1dfb553bf71c7 | |
parent | 8e5a2ab3614da2676a3627cf62fedfedf7f3585c (diff) | |
download | nova-dbb3358f851c245ccb5ea9a9c7ace636b4e73a80.tar.gz nova-dbb3358f851c245ccb5ea9a9c7ace636b4e73a80.tar.xz nova-dbb3358f851c245ccb5ea9a9c7ace636b4e73a80.zip |
simplified query
-rw-r--r-- | nova/db/sqlalchemy/api.py | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 5ec477666..18a43cad4 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -246,23 +246,15 @@ def fixed_ip_disassociate(_context, address): def fixed_ip_disassociate_all_by_timeout(_context, host, time): session = get_session() - # NOTE(vish): The annoying nested select here is because SQLite doesn't - # support JOINs in UPDATEs and Mysql doesn't support SELECT - # from the same table you are updating without using a temp - # table. It would be great if we can coax sqlalchemy into - # generating this update for us without having to update - # each fixed_ip individually. + # NOTE(vish): The nested select is because sqlite doesn't support + # JOINs in UPDATEs. result = session.execute('UPDATE fixed_ips SET instance_id = NULL, ' 'leased = 0 ' - 'WHERE id IN (SELECT x.id FROM ' - '(SELECT fixed_ips.id FROM fixed_ips ' - 'INNER JOIN networks ' - 'ON fixed_ips.network_id = ' - 'networks.id ' - 'WHERE networks.host = :host ' - 'AND fixed_ip.updated_at < :time ' - 'AND fixed_ip.instance_id IS NOT NULL ' - 'AND fixed_ip.allocated = 0) as x) ', + 'WHERE network_id IN (SELECT id FROM networks ' + 'WHERE host = :host) ' + 'AND updated_at < :time ' + 'AND instance_id IS NOT NULL ' + 'AND allocated = 0', {'host': host, 'time': time.isoformat()}) return result.rowcount |