Score:1

Should I use Aggregation or Query Settings > Distinct to remove duplicate results?

in flag

I have a basic view that displays published article teasers. The view has a contextual filter on the article content type's tags field, e.g. field_tags. The contextual filter is configured to accept multiple ids, e.g. 1+2+3 for OR.

When I pass 1+2+3 for the contextual filter's value, if an article has more than one of the passed values in field_tags, the article appears multiple times in the results.

I can easily remove the duplicate results by checking the Advanced > Query settings > Distinct checkbox. However, there's a warning with this checkbox stating that it may slow down the query:

This will make the view display only distinct items. If there are multiple identical items, each will be displayed only once. You can use this to try and remove duplicates from a view, though it does not always work. Note that this can slow queries down, so use it with caution.

Alternatively, I can remove duplicate results by enabling Advanced > Use aggregation. This option doesn't have a warning about performance, but I imagine it must also slow down my query.

Both methods are effective for removing duplicate results from my view. With this simple view, I don't expect any performance issues, but:

What's the difference between Advanced > Use aggregation vs Advanced > Query settings > Distinct to remove duplicates? Which is more performant?

cn flag
This is a plain SQL question rather than a Drupal one, it’s just a question of `SELECT DISTINCT` vs `GROUP BY`. See https://stackoverflow.com/questions/581521/whats-faster-select-distinct-or-group-by-in-mysql for lots of info
sonfd avatar
in flag
@Clive I see, thank you. I think it would be helpful to have the difference between the two options logged here. As far as performance goes, that is definitely better answered on another site. If you want to post your comment as an answer, I'll accept it. Thanks agin.
Jaypan avatar
de flag
This guy prefers aggregation: https://sqlperformance.com/2017/01/t-sql-queries/surprises-assumptions-group-by-distinct
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.