From bd5ae84e903c4f7338683a4db2cb4dc868ce38b4 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Mon, 18 Apr 2016 18:49:58 +0200 Subject: [PATCH] Optimize CDB_ColumnNames This implementation is about 1000 times faster --- scripts-available/CDB_ColumnNames.sql | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/scripts-available/CDB_ColumnNames.sql b/scripts-available/CDB_ColumnNames.sql index ce74216..22842bd 100644 --- a/scripts-available/CDB_ColumnNames.sql +++ b/scripts-available/CDB_ColumnNames.sql @@ -2,15 +2,13 @@ CREATE OR REPLACE FUNCTION CDB_ColumnNames(REGCLASS) RETURNS SETOF information_schema.sql_identifier AS $$ - - SELECT c.column_name - FROM information_schema.columns c, pg_class _tn, pg_namespace _sn - WHERE table_name = _tn.relname - AND table_schema = _sn.nspname - AND _tn.oid = $1::oid - AND _sn.oid = _tn.relnamespace - ORDER BY ordinal_position; - + SELECT + a.attname::information_schema.sql_identifier column_name + FROM pg_class c + LEFT JOIN pg_catalog.pg_attribute a ON a.attrelid = c.oid + WHERE c.oid = $1::oid + AND a.attstattarget = -1 + ORDER BY a.attnum; $$ LANGUAGE SQL; -- This is to migrate from pre-0.2.0 version