Author Topic: [SOLVED] - UpdateMedia mysql queries takes 100% CPU on a core - is that normal ?  (Read 16306 times)

Viking

  • Addicted
  • *
  • Posts: 521
    • View Profile
Hi,

don't have much time at the moment. But would like to give you some hints for going on :)
If you have queries where you can't find out what to do send me a PM. I will also try to follow this. But I have got lots of work and three sick kids, so not much time.


If you would like to find out which are the slow queries, activate this (remove the #) in /etc/mysql/my.cnf :

#log_slow_queries       = /var/log/mysql/mysql-slow.log
#long_query_time = 10
#log-queries-not-using-indexes


Note : "long_query_time" means the time that a query should run before it gets into the logfile. A good start is probably 10 seconds, but for some things you can also go lower ;)

And do a

/etc/init.d/mysql restart


After that use try to show the video datagrid and take a look in the "/var/log/mysql/mysql-slow.log" logfile.
You can the take the query from there an execute it on it's own.

I di not have time to look at the UpdateMedia query after the optimizing, but before it use 215 millions rows to get it done. That will prbably clear the query_cache ;)

You should not run you system permanently with this turned on though. The log will grow quite big.


-------

To find out what is actually done use this :

EXPLAIN EXTENDED <query>;
SHOW WARNINGS;


In the Update Media query that looked like this. As you can see in "before" it uses temp tables (using temporary) and "after" it is using indexes. That is a lot faster :)
So if a query uses temp tables , we can probably improve performance with indexes.


BEFORE :

+----+--------------+----------------+--------+-----------------+---------+---------+-----------------------------------------+-------+----------------------------------------------+
| id | select_type  | table          | type   | possible_keys   | key     | key_len | ref                                     | rows  | Extra                                        |
+----+--------------+----------------+--------+-----------------+---------+---------+-----------------------------------------+-------+----------------------------------------------+
|  1 | PRIMARY      | <derived2>     | ALL    | NULL            | NULL    | NULL    | NULL                                    | 35553 | Using where; Using temporary; Using filesort |
|  2 | DERIVED      | File           | ALL    | Path,Filename   | NULL    | NULL    | NULL                                    | 33257 | Using where; Using temporary; Using filesort |
|  2 | DERIVED      | Bookmark       | ALL    | NULL            | NULL    | NULL    | NULL                                    |   170 |                                              |
|  3 | UNION        | File           | ALL    | Path,Filename   | NULL    | NULL    | NULL                                    | 33257 | Using where; Using temporary; Using filesort |
|  3 | UNION        | File_Attribute | ref    | PRIMARY,FK_File | FK_File | 4       | pluto_media.File.PK_File                |     2 | Using index                                  |
|  3 | UNION        | Attribute      | eq_ref | PRIMARY         | PRIMARY | 4       | pluto_media.File_Attribute.FK_Attribute |     1 |                                              |
|  4 | UNION        | File           | ALL    | Path,Filename   | NULL    | NULL    | NULL                                    | 33257 | Using where; Using temporary; Using filesort |
|  4 | UNION        | LongAttribute  | ALL    | NULL            | NULL    | NULL    | NULL                                    |  2424 |                                              |
|  5 | UNION        | File           | ALL    | Path,Filename   | NULL    | NULL    | NULL                                    | 33257 | Using where; Using temporary; Using filesort |
|  5 | UNION        | Picture_File   | ref    | FK_File         | FK_File | 4       | pluto_media.File.PK_File                |     1 |                                              |
| NULL | UNION RESULT | <union2,3,4,5> | ALL    | NULL            | NULL    | NULL    | NULL                                    |  NULL |                                              |
+----+--------------+----------------+--------+-----------------+---------+---------+-----------------------------------------+-------+----------------------------------------------+
11 rows in set, 1 warning (1 min 10.85 sec)


AFTER :

+----+--------------+----------------+--------+-----------------+------------+---------+-----------------------------------------+-------+----------------------------------------------+
| id | select_type  | table          | type   | possible_keys   | key        | key_len | ref                                     | rows  | Extra                                        |
+----+--------------+----------------+--------+-----------------+------------+---------+-----------------------------------------+-------+----------------------------------------------+
|  1 | PRIMARY      | <derived2>     | ALL    | NULL            | NULL       | NULL    | NULL                                    | 60213 | Using where; Using temporary; Using filesort |
|  2 | DERIVED      | File           | index  | Path,Filename   | FatGroupBy | 546     | NULL                                    | 32007 | Using where                                  |
|  2 | DERIVED      | Bookmark       | ref    | FK_File         | FK_File    | 5       | pluto_media.File.PK_File                |     1 |                                              |
|  3 | UNION        | File           | index  | Path,Filename   | FatGroupBy | 546     | NULL                                    | 32007 | Using where                                  |
|  3 | UNION        | File_Attribute | ref    | PRIMARY,FK_File | FK_File    | 4       | pluto_media.File.PK_File                |     2 | Using index                                  |
|  3 | UNION        | Attribute      | eq_ref | PRIMARY         | PRIMARY    | 4       | pluto_media.File_Attribute.FK_Attribute |     1 |                                              |
|  4 | UNION        | File           | index  | Path,Filename   | FatGroupBy | 546     | NULL                                    | 32007 | Using where                                  |
|  4 | UNION        | LongAttribute  | ref    | FK_File         | FK_File    | 5       | pluto_media.File.PK_File                |     1 |                                              |
|  5 | UNION        | File           | index  | Path,Filename   | FatGroupBy | 546     | NULL                                    | 32007 | Using where                                  |
|  5 | UNION        | Picture_File   | ref    | FK_File         | FK_File    | 4       | pluto_media.File.PK_File                |     1 |                                              |
| NULL | UNION RESULT | <union2,3,4,5> | ALL    | NULL            | NULL       | NULL    | NULL                                    |  NULL |                                              |
+----+--------------+----------------+--------+-----------------+------------+---------+-----------------------------------------+-------+----------------------------------------------+
11 rows in set, 1 warning (7.92 sec)

--------

Some more things to try.

mysql>set profiling=1
mysql> Do things ( run qurey)
mysql>show profiles;
 
and get some more details for what we did :
 
mysql>show profile [all|block io|context switches|ipc|page faults|source|swaps] for query X;
 
 
Documentation: http://dev.mysql.com/doc/refman/5.0/en/show-profiles.html


--------

Last, iIf we use temp tables, we could try getting the to fit into memory - but better would be not to need that :
http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_max_heap_table_size
http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_tmp_table_size

That did not help anything on the UpdateMedia query - i tried it.


Greetings
Viking

phenigma

  • LinuxMCE God
  • ****
  • Posts: 1758
    • View Profile
Thanks Viking, I'll do some more investigating when I get home from work.

J.

colinjones

  • Alumni
  • LinuxMCE God
  • *
  • Posts: 3003
    • View Profile
hmmm... I don't get it, guys...

My data grids populate pretty much instantly all the time. I have about 1750 avi files, and probably lots more as mkv, mp4, etc. I usually use Filename sort mode which obviously isn't going to run the same big queries, so I just tested using Title... same results. It populates in like 0.5 seconds.

I tried /etc/init.d/mysql restart, then tried it again (on the basis that presumably restarting the SQL server would flush any caches) the first time it seemed to take about 1 second to populate, and subsequent retries back to 0.5 seconds. I note that only a relatively small percentage of my media files have artwork assigned, in case that slows things down (wouldn't think so, as it should only be retrieving the artwork for the tiles that are actually in the display at the time, so probably no more than 20 images)

When I type /etc/init.d/mysql status the SQL server had been running for 25 days and had executed about 12 million queries (ave around 5 per second), but only about 600 were considered "long". That being said, the cnf file has the "long" query defined as 2 seconds commented out, so I'm not sure how it is determining which queries are long!

Obviously I don't want my queries to take as long as yours! But I'm a bit baffled as to why they don't. (using 0710 btw)

jimbodude

  • Guru
  • ****
  • Posts: 372
    • View Profile
...You must be doing something special...  I'm looking at a pretty noticeable delay, and I have much less than 1000 video files...  Mine are all fully tagged, mostly ISOs, with cover-art.  I haven't timed it, but I'd say it's taking at least 3-5 seconds to get the orbiter updated.  Not sure if that's an SQL issue or not, though - it performs much better with my new Wireless AP, before I was looking at about 10 seconds...  The web orbiter is also noticeably slow, but harder to put my finger on how long that takes.  I don't usually use the on-screen orbiter, so I can't compare to that right now.  I'll look into it more if someone needs more data.

In 14 days of uptime, I have 9.6 million queries, average of 7.6 query/second, 1 slow query.  Using whatever the default is for slow query time.  The slow query log doesn't exist.  This is in 0810, last updated a week or two ago.

phenigma

  • LinuxMCE God
  • ****
  • Posts: 1758
    • View Profile
Artwork may be a contributing factor then, almost all of my media has artwork.  I can see the memory being allocated for the query in mysql when I select Audio or Video button in orbiter (takes ~7s).  The Audio query occupies a about 570Kb in the cache on my system.  I return to the home menu and select audio, the artists now display in about 0.5s.  As I monitor the cache in mysql after a couple minutes a 570kb chunk is freed from the cache memory.  Selecting audio again takes ~7s and about 570kb is added to the query_cache.  Mysql is abosolutely removing the query from the cache every few minutes on my system.  I'm not home from work yet but I'm going to dig around a bit more when I get home.

J.

jimbodude

  • Guru
  • ****
  • Posts: 372
    • View Profile
Which orbiter are your "time to display" estimates coming from? On Screen?  I'll experiment a bit also, if I don't get in too late, and let you know what I find.

phenigma

  • LinuxMCE God
  • ****
  • Posts: 1758
    • View Profile
Predominantly my Windows Orbiter.

The behaviour:
device, time uncached, time cached
WinOrbiter, ~7s, <1s (UI1)
Nokia N800, ~10s, ~3s (UI1)
WebDT 366, ~7s, ~2s (UI1)
p42.8 Core, ~7s, <1s (UI2 mask)
Zotac ION MD, ~7, <1s (UI2 mask)

When the query is executed and not present in the cache, top shows mysql using 90-100% of the processor for nearly the entire 7s time period, and it doesn't even show up as a blip in top when the query is in the cache.  I'm about to investigate some of the slow query logging options Viking pointed out and see what I can find out.

J.

phenigma

  • LinuxMCE God
  • ****
  • Posts: 1758
    • View Profile
Okay, the two queries are large but I see what they're doing, they're too large to post here so I've put them on pastebin.

The audio query results from mysql-slow.log show each query took 6 seconds to execute:
# Time: 091117 19:44:46
# User@Host: root[root] @ localhost []
# Query_time: 6  Lock_time: 0  Rows_sent: 627  Rows_examined: 117280

The video query from mysql-slow.log:
# Time: 091117 19:44:56
# User@Host: root[root] @ localhost []
# Query_time: 6  Lock_time: 0  Rows_sent: 8594  Rows_examined: 954413

The audio query results of the EXPLAIN EXTENDED & SHOW WARNINGS> http://pastebin.com/f5efcf4a7
The video query results of the EXPLAIN EXTENDED & SHOW WARNINGS> http://pastebin.com/f711a0612

The audio and video query results clearly show temporary tables being used rather than indexes.

J

jimbodude

  • Guru
  • ****
  • Posts: 372
    • View Profile
You beat me to it... I see similar results here.

colinjones

  • Alumni
  • LinuxMCE God
  • *
  • Posts: 3003
    • View Profile
How are you determining the amount of cache space consumed by the query?

I would have assumed that the query to create the collection of files would not have also retrieved the artwork. Only once Orbiter determines how many and which files are needed for the onscreen grid would it then query and return the artwork for those files only. In which case the artwork assigned shouldn't matter.....

tkmedia

  • wants to work for LinuxMCE
  • **
  • Posts: 937
    • View Profile
    • LMCECompatible
Not sure if this has any significance but after adding indexes i noticed a speed improvement in populating the grids on my web pad orbiter.

The strange thing is the text in the grid updates almost immediately then 1-2 seconds later the artwork updates.
Not sure if the delay is caused by the drawing of the graphic though.

For whatever thats worth.



Tim
My Setup http://wiki.linuxmce.org/index.php/User:Tkmedia

For LinuxMce compatible  systems and accessories
http://lmcecompatible.com/

phenigma

  • LinuxMCE God
  • ****
  • Posts: 1758
    • View Profile
How are you determining the amount of cache space consumed by the query?

You can monitor the status of the query cache like this:
Code: [Select]
mysql> SHOW STATUS LIKE 'Qcache%';
+-------------------------+----------+
| Variable_name           | Value    |
+-------------------------+----------+
| Qcache_free_blocks      | 16       |
| Qcache_free_memory      | 13297728 |
| Qcache_hits             | 57112    |
| Qcache_inserts          | 5118     |
| Qcache_lowmem_prunes    | 0        |
| Qcache_not_cached       | 31260    |
| Qcache_queries_in_cache | 1951     |
| Qcache_total_blocks     | 3978     |
+-------------------------+----------+
8 rows in set (0.00 sec)

And with out the filter you can see more mysql information.
Code: [Select]
SHOW STATUS;
Quote
I would have assumed that the query to create the collection of files would not have also retrieved the artwork. Only once Orbiter determines how many and which files are needed for the onscreen grid would it then query and return the artwork for those files only. In which case the artwork assigned shouldn't matter.....

Yes, you are correct as far as I can tell.  I don't see this being artwork related with the behaviour I'm observing.

J.

Viking

  • Addicted
  • *
  • Posts: 521
    • View Profile
Hi,

don't have time today, but will look at it tomorrow.

What strikes me. Why is it doing this :
"AND PK_File in (37968,37996,38006, ....."

It looks like there is an query before that which sorts out the files to look at. The question is then if it makes sence to split that up in two. But maybe we should just try and optimize the query first ;)


The second thing i posted gives some more infos :

# write output to a logfile
mysql --tee=/tmp/mysql-output.log

set profiling=1;
"run query"
show profile all;

That shows where the time has gone (second row) - for example if the problem is that it creates a temp table.

Here a cutout of the UpdateMedia query - you can see that it spents quite some time with "Copying to tmp table" and does some I/O (Block_ops_out) :

Code: [Select]
| Status                         | Duration  | CPU_user  | CPU_system | Context_voluntary | Context_involuntary | Block_ops_in | Block_ops_out | Messages_sent | Messages_received | Page_faults_major | Page_faults_minor | Swaps | Source_function         | Source_file   | Source_line |

| executing                      |  0.000004 |  0.000000 |   0.000000 |                 0 |                   0 |            0 |             0 |             0 |                 0 |                 0 |                 0 |     0 | exec                    | sql_select.cc |        1581 |
| Copying to tmp table           | 51.064221 | 77.472841 |   1.264079 |               746 |               23671 |            0 |         92152 |             0 |                 0 |                 0 |              2313 |     0 | exec                    | sql_select.cc |        1721 |

Not sure if that will get us further, but the more infos the better.

Greetings
Viking

Viking

  • Addicted
  • *
  • Posts: 521
    • View Profile
Hi again,

just did find time to find the query for my system and it puzzels me that every dvd/recording shows up not only once, but several times !? :
(there were more Evolution lies, had to remove thre to fit in 20000 chars limit)

Code: [Select]
|   46524 |  | Nyhederne                                                                                                                                          | 0 |             3 | 4004_20091117185800.mpg                                                               | NULL                |
|   46524 |  |                                                                                                                                                    | 0 |             3 | 4004_20091117185800.mpg                                                               | NULL                |
|   46524 |  |                                                                                                                                                    | 0 |             3 | 4004_20091117185800.mpg                                                               | NULL                |
|   46524 |  |                                                                                                                                                    | 0 |             3 | 4004_20091117185800.mpg                                                               | NULL                |
|   46524 |  |                                                                                                                                                    | 0 |             3 | 4004_20091117185800.mpg                                                               | NULL                |
|   42612 |  | Evolution                                                                                                                                          | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |
|   42612 |  |                                                                                                                                                    | 0 |          NULL | Evolution.ISO                                                                         | 2009-11-13 22:14:32 |


chriss

  • Veteran
  • ***
  • Posts: 140
    • View Profile
Hi Viking,

just did find time to find the query for my system and it puzzels me that every dvd/recording shows up not only once, but several times !? :

there is a command to prevent duplicate lines in result sets from mysql. Just try to do a "SELECT DISTINCT ..." instead of "SELECT ...". Reducing the result set of a query does also reduce resource usage, especially if the results are used to start another query.

Quote
What strikes me. Why is it doing this :
"AND PK_File in (37968,37996,38006, ....."

It looks like there is an query before that which sorts out the files to look at. The question is then if it makes sence to split that up in two. But maybe we should just try and optimize the query first.

Using nested queries should even speed up the process because the results do not have to be tranferred back and forth, i.e. try something like "SELECT ... FROM ... WHERE ... AND PK_File in (SELECT DISTINCT FK_File FROM ....)".

br,
/chriss
« Last Edit: November 19, 2009, 11:53:29 am by chriss »