speedup unique impressions #24

Merged
merged 1 commit into from Jan 20, 2012

Conversation

Projects
None yet
2 participants
Contributor

lacco commented Jan 19, 2012

When using the :unique option, then a impressions.count == 0is used to validate uniqueness. This requires a full table scan every time (without appropriate indexes):

SELECT COUNT(*) FROMimpressions``

Using !impressions.exists? results in a much more efficient query (but even requires a full table scan when there is no existing impression):

SELECT 1 FROMimpressionsLIMIT 1

@johnmcaliley johnmcaliley added a commit that referenced this pull request Jan 20, 2012

@johnmcaliley johnmcaliley Merge pull request #24 from lacco/speedup_unique
speedup unique impressions
7de8bd9

@johnmcaliley johnmcaliley merged commit 7de8bd9 into charlotte-ruby:master Jan 20, 2012

Owner

johnmcaliley commented Jan 20, 2012

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment