515
Views
12
Comments
Solved
Aggregate to return values of selected columns
Question

Is it possible to make an aggregate to return the values of selected columns alone?

Like we are able to query selected columns from an entity using SQL, can we do the same thing using aggregate?

mvp_badge
MVP
Rank: #2
Solution

Hi Ananth,

There's absolutely no need to do that. The Platform Optimizer will recognize which columns you use, and only use these in the underlying SELECT.

mvp_badge
MVP
Rank: #15

Hi Ananth,

In aggregates you don't need to worry about that because outsystems takes care of that for you and only queries the fields of the aggregate that you use/need.

Regards,

Marcelo

mvp_badge
MVP
Rank: #2

@Marcelo: I got there first! ;)

mvp_badge
MVP
Rank: #15

@Kilian Im on smartphone so I write a lot slower ;)

Rank: #432

If I want to force the aggregate to return only one column I use group by, but on this case might not be need

mvp_badge
MVP
Rank: #2

Nelson,

The only reason to limit the output would be if you want to pass it as Output Parameter, and you don't want to bother with creating a new Structure. However, using Group By comes with a performance penalty, so use it with care!

Rank: #14889

Hello All


After the web developer test sample, I was correcting my answers and I'm confused in question 14:


"14. Considering Aggregates in a Web application, which of the following options is false?"


The correct answer is: Aggregates allow hiding columns to reduce the number of attributes returned in the query.

What's the catch? I can hide columns to reduce .... 


Thank's in advance


Ricardo


mvp_badge
MVP
Rank: #2

Hi Ricardo,

That's not true. You can hide the number of columns you are seeing in preview mode, but that's independent of what is actually fetched when the app runs. The optimizer determines what Attributes are retrieved from the database.

Rank: #14889

Kilian Hekhuis wrote:

Hi Ricardo,

That's not true. You can hide the number of columns you are seeing in preview mode, but that's independent of what is actually fetched when the app runs. The optimizer determines what Attributes are retrieved from the database.


Thank You Kilian :-)

mvp_badge
MVP
Rank: #2

You're most welcome :). It can be a bit confusing I admit, but the takeaway is that the optimizer always minimizes the number of columns to fetch. Just be aware that as soon as you output the Aggregate result in an Action, all Attributes will be fetched, as the optimizer cannot know what you're planning to do with that output. Happy coding!

Rank: #5998

Hi Kilian, What's the definition of "output"? As a test I am displaying the sample_product Name in a drop down and thought I was only downloading ID and Name but (based on my limited understanding) Google Chrome is showing that I am also downloading image data. In the example below my 100 records of sample_products total 952kB and each image appears to be downloaded. Any explanation would be welcome...Thanks!

mvp_badge
MVP
Rank: #2

Hi Tim,

For Reactive (and Mobile) Apps, the situation is slightly different (the original topic here was from 2018, so before Reactive). Aggregate optimization for Reactive is introduced in version 11.10, and it might be you need to manually switch it on (I get my information partially from this article, section "Turn on Optimizer").