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

pkp/pkp-lib#9829 Attempt to improve the search query performance #4224

Open
wants to merge 1 commit into
base: stable-3_4_0
Choose a base branch
from

Conversation

jonasraoni
Copy link
Contributor

@jonasraoni jonasraoni commented Mar 24, 2024

The PR doesn't make miracles, some keywords might still be problematic, but it improved the situation.

@jonasraoni jonasraoni linked an issue Mar 24, 2024 that may be closed by this pull request
->whereColumn('ps.publication_id', '=', 'p.publication_id')
->where('ps.locale', '=', '')
)
->join('issues AS i', 'i.issue_id', '=', DB::raw('CAST(ps.setting_value AS ' . (DB::connection() instanceof MySqlConnection ? 'UNSIGNED' : 'INTEGER') . ')'))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The biggest improvement came from this modification.
I'll create another issue to move the issue_id to a physical field, I've seen this CAST() in several places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix that we've adopted internally (as these updates are not enough) was to handicap the search even more, I basically replaced these lines:

->groupBy('o.submission_id')
->orderByDesc('count')
->limit($limit)
->select(
'o.submission_id',
DB::raw('MAX(s.context_id) AS journal_id'),
DB::raw('MAX(i.date_published) AS i_pub'),
DB::raw('MAX(p.date_published) AS s_pub'),
DB::raw('COUNT(0) AS count')
);

By:

            ->limit($limit * 4)
            ->select(
                'o.submission_id',
                DB::raw('s.context_id'),
                DB::raw('i.date_published AS i_pub'),
                DB::raw('p.date_published AS s_pub')
            );

        $q = DB::query()
            ->fromSub($q, 'x')
            ->groupBy('x.submission_id')
            ->orderByDesc('count')
            ->select(
                'x.submission_id',
                DB::raw('MAX(x.context_id) AS journal_id'),
                DB::raw('MAX(x.i_pub) AS i_pub'),
                DB::raw('MAX(x.s_pub) AS s_pub'),
                DB::raw('COUNT(0) AS count')
            );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant