Skip to main content

Timeline for INNER JOIN making COUNT(*) slow

Current License: CC BY-SA 3.0

13 events
when toggle format what by license comment
Jan 15, 2018 at 17:14 comment added Lennart - Slava Ukraini Is the performance affected if you use a non-nullable column from messages in COUNT? I.e. SELECT COUNT(messages.message_id) FROM messages JOIN .... It should be possible for the optimizer to eliminate the join, check if that helps.
Jan 15, 2018 at 14:43 history edited Aaron Bertrand
edited tags
Aug 13, 2012 at 16:25 vote accept Darthtong
Aug 13, 2012 at 15:46 comment added Jean-Bernard Lagorce I don't see the point of the join, unless you plan to add filtering on the users table (an index on messages.user_id should help then would ) By now, it seems that a simple select count(message_id) from messages should do the trick
Aug 13, 2012 at 15:39 history edited Aaron Bertrand CC BY-SA 3.0
Removed tag from title (we know it's SQL Server).
Aug 13, 2012 at 15:36 history migrated from stackoverflow.com (revisions)
Aug 13, 2012 at 15:36 answer added podiluska timeline score: -1
Aug 13, 2012 at 15:34 comment added Martin Smith Please provide the CREATE TABLE statements including indexes and the execution plan.
Aug 13, 2012 at 15:34 answer added Clinton Ward timeline score: -1
Aug 13, 2012 at 15:34 answer added Aaron Bertrand timeline score: 5
Aug 13, 2012 at 15:32 comment added Darthtong No there will always be a match
Aug 13, 2012 at 15:31 comment added Aaron Bertrand Do you have any rows in messages where user_id won't be in users? (e.g. is the foreign key nullable)
Aug 13, 2012 at 15:30 history asked Darthtong CC BY-SA 3.0