Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize(Search): Handle LEFT JOIN which concern counting operations lastly #16999

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Search/Provider/SQLProvider.php
Expand Up @@ -3669,6 +3669,18 @@ public static function constructSQL(array &$data)
$COMMONLEFTJOIN = \Search::addDefaultJoin($data['itemtype'], $itemtable, $already_link_tables);
$FROM .= $COMMONLEFTJOIN;

// need to reorder $data['tocompute'] that contains searchoption ID
// to be sure that all LEFT JOIN related to count operation (searchoption datatype = count))
// are done after all other LEFT JOIN
$ordered_data_to_compute = $data['tocompute'];
foreach ($data['tocompute'] as $key => $val) {
if (isset($searchopt[$val]["datatype"]) && $searchopt[$val]["datatype"] == 'count') {
unset($ordered_data_to_compute[$key]); //remove key
array_push($ordered_data_to_compute, $val); //add it at end
}
}
$data['tocompute'] = $ordered_data_to_compute;

// Add all table for toview items
foreach ($data['tocompute'] as $val) {
if (!in_array($searchopt[$val]["table"], $blacklist_tables)) {
Expand Down