cancel
Showing results for 
Search instead for 
Did you mean: 

Cardinality in CDS assocation

eddy_declercq
Active Contributor
0 Kudos

Hi,

If I understand it correctly the cardinality only reflects the target table.

Does the cardinality have any influence at all - thus providing the wrong cardinality gives different results.

Or is this cardinality for documentaion purposes only since association is by default left outer join.

I see mixed messages about this matter.

Speaking of, what about the cardinality for the inner? I only see examples with [1:inner].

I see also examples with filters on inner without cardinality. A good explanation and/or documentation on all this would be very nice, since it's rather confusion with all these mixed/contradictional messages.

Cheers

Eddy

Accepted Solutions (0)

Answers (2)

Answers (2)

Sean_Zhang
Product and Topic Expert
Product and Topic Expert

The target cardinality of an association shall always be defined explicitly providing the minimum and maximum number of target instance occurences, for example [0..1] or [0..*].

It is recommended to increase the transparency of the model by always specifying the maximum cardinality of joins (...left outer to one join.../...left outer to many join...), which are used in the CDS view definition.

If fields are added to a view via joins with the addition "to one" or associations with the target cardinality [0/1..1] the corresponding joins shall only be executed if these fields are actually selected.

This is actually the influence.

because, for "to one" or associaiton cardinality [0/1..1], the generated SQL statement will be interpretated as LEFT out join to one. Then if the DB support the optimization and no fields from the right right is selected in the comsumer level, the join will be by passed. e.g. the HANA supports the optimization.

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

This is correct.

In fact we have platform dependent behavior here, because not all DBs optimize.

The documentation was enhanced and will deliver some examples with next release.

Sean_Zhang
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Horst,

Yes, the optimization is DB specific.

and it's also good to hear that there will be official document and example to explain this.

Best Regards,

Sean

eddy_declercq
Active Contributor
0 Kudos

I'm afraid it's still not clear to me if specifying the wrong cardinality has influence on the results (on a HANA DB) or not. If I read your answer it's best to specify always [0..*] for a left outer join. But what with an inner join? Specifying [1] or [1:inner]?

It's not clear to me what to do when one wants to create reusable views, where one needs sometimes a left outer join and in other cases en inner join for the same query.