Announcement

Announcement Module
Collapse
No announcement yet.

Query performs well if it is not optimized

Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Query performs well if it is not optimized

    Hi,

    If I issue this query, the results come very fast.
    SELECT SUM(metric_diff) FROM snapshot_master WHERE snapshot_master.metric_id = 5 AND snapshot_master.timestamp_id in (select timestamp_id from timestamp_master where server_timestamp >= 1202091795 AND server_timestamp <= 1202113395 and strftime("%Y-%m-%d %H:%M", datetime(server_timestamp, 'unixepoch',
    'localtime'))
    = (select strftime("%Y-%m-%d %H:%M", datetime(server_timestamp, 'unixepoch',
    'localtime')) from timestamp_master where timestamp_id = 36000))

    If I remove the sub-queries and try and join the tables, then the query takes a lot of time.

    The tables are well designed, PK is on the metric_id and timestamp_id columns, even I have created indexes on the server_timestamp column.

    Am I missing something?

    Chn
Working...
X