Create a user and device relationship mapping table, the user's device ID is stored in the array field:
CREATE TABLE device.user_devices
(
user_id character varying(32) COLLATE pg_catalog."default" NOT NULL,
device_ids character varying[] COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT user_devices_pkey PRIMARY KEY (user_id)
)
Import data into the table:
insert into device.user_devices
select device_owner, array_agg(device_id)
from device.device_info
where device_owner is not null
and device_owner != ''
group by device_owner
Compare the performance of the original query method and the new query method:
Original query method:
New query method:
It can be found that the performance of the new query method has been greatly improved!
{{o.name}}
{{m.name}}