brianhempel / active_record_union

UNIONs in ActiveRecord! Adds proper union and union_all methods to ActiveRecord::Relation.
Other
423 stars 41 forks source link

Added #union_all #3

Closed pic closed 9 years ago

pic commented 9 years ago

added support for "UNION ALL"

brianhempel commented 9 years ago

What's your use case for UNION ALL?

pic commented 9 years ago

as far as I know, UNION removes duplicates, UNION ALL does not, so it is faster. That is convenient when you do not need to remove duplicates ore where you already not that the two tables have an empty intersection

On Thu, Mar 19, 2015 at 3:17 PM, Brian Hempel notifications@github.com wrote:

What's your use case for UNION ALL?

— Reply to this email directly or view it on GitHub https://github.com/brianhempel/active_record_union/pull/3#issuecomment-83596831 .

brianhempel commented 9 years ago

Do you have a use for it? (What inspired you to make the PR?)

pic commented 9 years ago

yes, I want to use it in a query I have which is quite slow and I hope I can improve the speed with UNION ALL. Moreover, in my case, it is totally fine to UNION ALL because the two tables should not have duplicates.

Sorry but I do not have numbers about difference in speed in my case yet, it is a work in progress. As soon as I have time I want to bundle with my fork and try the same query with union_all and compare.

To be completely honest, I do not think that UNION ALL will be enough to solve my speed problem, so in the end I will have to change something else, I think.

On Thu, Mar 19, 2015 at 3:23 PM, Brian Hempel notifications@github.com wrote:

Do you have a use for it? (What inspired you to make the PR?)

— Reply to this email directly or view it on GitHub https://github.com/brianhempel/active_record_union/pull/3#issuecomment-83602600 .

brianhempel commented 9 years ago

Thanks. I think I am in favor of adding it. Bug me in a week if I haven't merged this.

pic commented 9 years ago

FYI: in my case UNION ALL was really useful.

I have this table, it is not big, just 20k records, but I have a complex query on it, something like: (a JOIN b JOIN c) union (a JOIN b JOIN c) with various WHERE / ORDER .

Using UNION it used to take 4 seconds to run, with UNION ALL it is down 0.1 second.

Best regards

On Thu, Mar 19, 2015 at 3:35 PM, Brian Hempel notifications@github.com wrote:

Thanks. I think I am in favor of adding it. Bug me in a week if I haven't merged this.

— Reply to this email directly or view it on GitHub https://github.com/brianhempel/active_record_union/pull/3#issuecomment-83611018 .

brianhempel commented 9 years ago

Version 1.1.0 is now available on Rubygems with UNION ALL support. Thanks for the PR!