Get all distinct values of array column PostgreSQL

I have a table that has around 400000 records and lets say it looks like this:

UUID   | setting_ids
------------------
 1     |  {1,8}
 2     | {4, 69, 7}
 3     |   { }
 4     |   {2}
...
400000 | {1, 2, 3}

I have to return all distinct setting ids of column setting_ids which is array type. Right now I have a query like this and it takes around 600ms to execute, which is too slow. I have GIN index on settingIDs but I don't know how to use it right for this type of query.

WITH "t_setting" AS (
        SELECT "t"."setting_ids"
        FROM "test" "t"

), "testt" AS (
        SELECT UNNEST("setting_ids") AS "setting_id"
        FROM "t_setting"
)
SELECT ARRAY_AGG(DISTINCT "setting_id")
FROM "testt"

Thanks for your help!

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum