From 8929b4eea93940728ff0377002fb486af1275e82 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 25 Oct 2017 12:05:28 -0400 Subject: [PATCH] try using correlated subquery for unique list of keys, is pretty slow --- srce_defn.pgsql | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/srce_defn.pgsql b/srce_defn.pgsql index 79046fb..65361c3 100644 --- a/srce_defn.pgsql +++ b/srce_defn.pgsql @@ -1,17 +1,24 @@ +\timing +/* WITH ext AS ( SELECT srce ,defn->'unique_constraint'->>'fields' - ,ARRAY(SELECT ae.e::text[] FROM jsonb_array_elements_text(defn->'unique_constraint'->'fields') ae(e)) txa + ,ARRAY(SELECT ae.e::text[] FROM jsonb_array_elements_text(defn->'unique_constraint'->'fields') ae(e)) text_array FROM tps.srce + --add where clause for targeted source ) -SELECT - srce - , - public.jsonb_extract(rec,txa) +*/ + +SELECT COUNT(*) FROM +( +SELECT DISTINCT + t.srce + ,(SELECT JSONB_OBJECT_agg(ae.e,rec #> ae.e::text[]) FROM jsonb_array_elements_text(defn->'unique_constraint'->'fields') ae(e)) ja FROM - tps.trans - INNER JOIN ext ON - trans.srce = ext.srce \ No newline at end of file + tps.trans t + INNER JOIN tps.srce s ON + s.srce = t.srce +) X \ No newline at end of file