Hi Team,
We had screen UI query which is taking 75s to load. Could you please help us to optimize further.
SELECT DISTINCT d.name,
CASE WHEN EVERY v IN d.countryname SATISFIES v = -1 END THEN "All countries selected" ELSE d.countryname END AS countryname,
CASE WHEN EVERY v IN f.networkname SATISFIES v = -1 END THEN "All networks selected" ELSE f.networkname END AS networkname,
d.hpmn,
d.status,
d.used,
d.enabled,
d.grptype,
d.numtype,
d.negation,
d.id,
d.countryid,
f.networkid,
d.__by,
d.__at
FROM(
SELECT CASE WHEN EVERY v IN ARRAY_FLATTEN(c.cntrynw[*].nwid,2) SATISFIES v = -1 END THEN (
SELECT DISTINCT f.name,
TONUMBER(SPLIT(META(f).id, ':')[1]) AS hpmn,
ARRAY_FLATTEN(f.cntrynw[*].nwid,2) AS networkid,
ARRAY_FLATTEN(f.cntrynw[*].nwid,2) AS networkname
FROM config f
UNNEST ARRAY_FLATTEN(f.cntrynw[*].nwid,2) AS netid
WHERE f.__t='vf-group-master'
AND f.status <> 2
AND EVERY v IN ARRAY_FLATTEN(f.cntrynw[*].nwid,2) SATISFIES v = -1 END) ELSE (
SELECT DISTINCT b.name,
TONUMBER(SPLIT(META(b).id, ':')[1]) AS hpmn,
ARRAY_AGG(networkid) AS networkid,
REPLACE(REPLACE(REPLACE(ENCODE_JSON(ARRAY_FLATTEN(ARRAY_AGG(d.networkname || " (" || d.gsm[0].mcc || "," || d.gsm[0].mnc || ")"), 1)), "\",\"", ","), "[\"",""), "\"]", "") AS networkname
FROM config b
UNNEST ARRAY_FLATTEN(b.cntrynw[*].nwid,2) AS networkid
INNER JOIN `config` AS d USE HASH(BUILD) ON d.networkid = networkid
WHERE b.__t = 'vf-group-master'
AND d.__t='irdb-net'
AND b.status <> 2
GROUP BY b.name,
TONUMBER(SPLIT(META(b).id, ':')[1])) END AS networkdata,
CASE WHEN EVERY v IN c.cntrynw[*].ctryid SATISFIES v = -1 END THEN (
SELECT DISTINCT f.name,
f.status,
f.used,
f.__by,
f.__at,
TONUMBER(SPLIT(META(f).id, ':')[1]) AS hpmn,
f.cntrynw[*].ctryid AS countryname,
f.enabled,
f.grptype,
f.numtype,
f.negation,
f.cntrynw[*].ctryid AS countryid,
TONUMBER(SPLIT(META(f).id, ':')[2]) AS id
FROM config f
WHERE f.__t='vf-group-master'
AND status <> 2
AND EVERY v IN f.cntrynw[*].ctryid SATISFIES v = -1 END) ELSE (
SELECT DISTINCT b.name,
b.status,
b.used,
TONUMBER(SPLIT(META(b).id, ':')[1]) AS hpmn,
b.enabled,
b.grptype,
b.numtype,
b.__by,
b.__at,
b.negation,
TONUMBER(SPLIT(META(b).id, ':')[2]) AS id,
REPLACE(REPLACE(REPLACE(ENCODE_JSON(ARRAY_FLATTEN(ARRAY_AGG(DISTINCT d.countryname || " (" || d.gsm[0].cc || ")"), 1)), "\",\"", ","), "[\"",""), "\"]", "") AS countryname,
ARRAY_AGG(countryid) AS countryid
FROM config b
UNNEST b.cntrynw[*].ctryid AS countryid
INNER JOIN `config` AS d USE HASH(BUILD) ON d.countryid = countryid
WHERE b.__t = 'vf-group-master'
AND d.__t='irdb-country'
AND b.status <> 2
GROUP BY b.name,
b.status,
b.used,
TONUMBER(SPLIT(META(b).id, ':')[1]),
b.enabled,
b.grptype,
b.numtype,
b.negation,
b.__by,
b.__at,
TONUMBER(SPLIT(META(b).id, ':')[2])) END AS countrydata
FROM config c
WHERE c.__t='vf-group-master'
AND c.status <> 2)m
UNNEST m.countrydata AS d
UNNEST m.networkdata AS f
WHERE f.name= d.name
AND d.hpmn = f.hpmn
Thanks,
Debasis
plan_test_1602.zip (5.8 KB)