Pagination/Count sqls with union
are really slow
#46041
Unanswered
parallels999
asked this question in
Q&A
Replies: 1 comment 2 replies
-
$audits_1_count = DB::table('audits_1')->count();
$audits_2_count = DB::table('audits_2')->count();
$total_count = $audits_1_count + $audits_2_count;
$result = DB::table(DB::raw(''))
->selectRaw('(?) as aggregate', [$total_count])
->get(); @parallels999 Would not the above Laravel code is similar to: select (
select count(*) as aggregate from `audits_1`
+ select count(*) as aggregate from `audits_2`
) as aggregate; I wonder if it does faster tho. How can I measure the processing time of the above code? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Current SQL looks like this
How about querying each sql individually by union for avoid getting all the columns before the count?
Sow now we can accumulate results (count_0 + count_1 + count_n)
Also
framework/src/Illuminate/Database/Query/Builder.php
Lines 2789 to 2794 in df696e9
Beta Was this translation helpful? Give feedback.
All reactions