Skip to content

Commit

Permalink
core: in sql use 'any' instead of 'select unnest' (#3181)
Browse files Browse the repository at this point in the history
This helps the query optimizer to analyze the query.
  • Loading branch information
mworrell committed Nov 14, 2022
1 parent 23bb03b commit fa9c775
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion modules/mod_search/support/search_query.erl
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ parse_query([{content_group, ContentGroup}|Rest], Context, Result0) ->
true ->
List = m_hierarchy:contains(<<"content_group">>, ContentGroup, Context),
{Arg, Result1} = add_arg(List, Result),
add_where("rsc.content_group_id IN (SELECT(unnest("++Arg++"::int[])))", Result1);
add_where("rsc.content_group_id = any("++Arg++"::int[])", Result1);
false ->
{Arg, Result1} = add_arg(ContentGroupId, Result),
add_where("rsc.content_group_id = "++Arg, Result1)
Expand Down
2 changes: 1 addition & 1 deletion src/models/m_edge.erl
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ delete_multiple(SubjectId, Preds, ObjectId, Context) ->
from edge
where subject_id = $1
and object_id = $2
and predicate_id in (SELECT(unnest($3::int[])))",
and predicate_id = any($3::int[])",
[SubjectId, ObjectId, PredIds], Ctx)
end,

Expand Down
2 changes: 1 addition & 1 deletion src/support/z_search.erl
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ add_cat_exact_check([], _Alias, WAcc, As, _Context) ->
add_cat_exact_check(CatsExact, Alias, WAcc, As, Context) ->
CatIds = [ m_rsc:rid(CId, Context) || CId <- CatsExact ],
{WAcc ++ [
[Alias, [ ".category_id in (SELECT(unnest($", (integer_to_list(length(As)+1)), "::int[])))"] ]
[Alias, [ ".category_id = any($", (integer_to_list(length(As)+1)), "::int[])"] ]
],
As ++ [CatIds]}.

0 comments on commit fa9c775

Please sign in to comment.