Limit Multivalue Fields

Multivalue fields can cause poor performance. The behavior of these fields is undefined for group-by and foreach statements. If possible, write your query so that the fields are referenced only in filters.

To work with multivalue fields, from Setup, in the Quick Find box, enter Analytics, and then select Settings. In Settings, click the checkbox for Enable indexing of multivalue fields in CRM Analytics. If you don’t select this preference, the mv_to_string() function returns only the first value in the field. See mv_to_string() for more information.

Even with indexing enabled, multivalue fields in multilevel grouping, such as group by(Year, Region), can cause poor performance.

Note

Here’s FlightsMV, a sample dataset of flight information.

airlineflight_numorigindestpilotairplaneflight_classesflight_attendantsdistancenum_passengers
southwestsw301laxsfojohnboeing 737-700business;economymark;sara;kate;maria;martin1000100
unitedu321laxsfomarkboeing 737-900first;business;economyjen;sophia;emma;alice1000200
alaskaas400laxsfotimairbus A320business;economymark;leila;brad1000100
deltad301laxsfomartinairbus A321business;economysarah;maria1000100
southwestsw302sfolax- business;economy-1000100
unitedu322sfolaxjohnboeing 737-700first;business;economysarah;martin1000200
alaskaas401sfolaxmarkboeing 737-900business;economymaria;mark;sara;kate;martin1000100
deltad302sfolaxtimairbus A320business;economyemma;jen;sophia;alice1000100
southwestsw303laxjfkrobertairbus A321business;economyleila;mark;brad1000100
unitedu323laxjfkmaria first;business;economy-1000200
alaskaas403laxjfkmarkboeing 737-700business;economy-1000100
deltad303laxjfktimboeing 737-900business;economymaria;sarah1000100
southwestsw304jfklaxrobertairbus A320business;economymartin;sarah1000100
unitedu324jfklax-airbus A321first;business;economykate;mark;sara;maria;martin1000200
alaskaas404jfklaxjohn business;economysophia;jen;emma;alice1000100
deltad304jfklaxmarkboeing 737-700business;economy-1000100
southwestsw303laxordmartinboeing 737-900business;economy-1000100
unitedu323laxordrobertairbus A320first;business;economy 1000200
alaskaas403laxord-airbus A321business;economybrad;mark;leila1000100
deltad303laxordjohn-business;economysarah;maria1000100

The flight_attendants column contains multivalue fields. Let’s write a query to filter on the rows where maria is listed as a flight attendant.

1q = load "FlightsMV";
2q = filter q by 'flight_attendants' in ["maria"];
3q = foreach q generate 'airplane' as 'airplane', 'distance' as 'distance', 'flight_attendants' as 'flight_attendants', 'flight_num' as 'flight_num', 'id' as 'id', 'num_passengers' as 'num_passengers', 'origin' as 'origin', 'pilot' as 'pilot';
airplanedistanceflight_attendantsflight_numidnum_passengersoriginpilot
boeing 737-7001000katesw3011100laxjohn
airbus A3211000mariad3014100laxmartin
boeing 737-9001000kateas4017100sfomark
boeing 737-9001000mariad30312100laxtim
airbus A3211000kateu32414200jfk-
-1000mariad30320100laxjohn

The results display the rows that include maria. The flight_attendants field displays only one flight attendant name when the field is multivalue. To return all the names, use the mv_to_string() function.

1q = load "FlightsMV";
2q = filter q by 'flight_attendants' in ["maria"];
3q = foreach q generate 'airplane' as 'airplane', 'distance' as 'distance', mv_to_string('flight_attendants') as 'flight_attendants', 'flight_num' as 'flight_num', 'id' as 'id', 'num_passengers' as 'num_passengers', 'origin' as 'origin', 'pilot' as 'pilot';

When using comparison operators in the filter, use in and not in to return the correct values. Using == and != returns unexpected values when null handling is enabled. See Group-by with Null Values for more information.

Note

See Also