Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VsVt9-0005Pt-PZ for pgsql-sql@arkaria.postgresql.org; Mon, 16 Dec 2013 10:59:03 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VsVt9-00025N-4P for pgsql-sql@arkaria.postgresql.org; Mon, 16 Dec 2013 10:59:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VsVt8-00025G-4f for pgsql-sql@postgresql.org; Mon, 16 Dec 2013 10:59:02 +0000 Received: from adsltrust.ath.forthnet.gr ([194.219.204.174] helo=smadev.internal.net) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VsVt5-00020T-2i for pgsql-sql@postgresql.org; Mon, 16 Dec 2013 10:59:01 +0000 Received: from smadev.internal.net (smadev [10.9.200.131]) by smadev.internal.net (8.14.7/8.14.7) with ESMTP id rBGAwuZU065859 for ; Mon, 16 Dec 2013 12:58:56 +0200 (EET) (envelope-from achill@matrix.gatewaynet.com) Message-ID: <52AEDCF0.8000606@matrix.gatewaynet.com> Date: Mon, 16 Dec 2013 12:58:56 +0200 From: Achilleas Mantzios User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Query caching (with 8.3) Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Hello list, i was wondering is there is some way of speeding up results of a query in postgresql 8.3 (upgrading is not an option for the moment). Basically this is a small function querying information_schema for tables, columns satisfying specific criteria : CREATE OR REPLACE FUNCTION xid_tables_cols(OUT table_name TEXT, OUT column_name TEXT, OUT data_type TEXT) RETURNS SETOF record AS $$ DECLARE BEGIN RETURN QUERY SELECT c.table_name::text,c.column_name::text,c.data_type::text FROM information_schema.columns c WHERE c.table_schema='public' AND c.table_name LIKE '%_tmp' AND c.data_type IN ('bytea','text') AND EXISTS (SELECT 1 FROM information_schema.columns c2 WHERE c2.table_schema='public' AND c2.table_name=c.table_name AND c2.column_name='xid'); RETURN; END; $$ LANGUAGE plpgsql STABLE; The whole point is to be able to calculate row/columns sizes based on data type, by automatically finding all those tables that apply to our specific technique/architecture (all tables whose name end in _tmp, and in addition who have at least one column named "xid"). This query is slow in 8.3. In 9.2 this is a non-issue. The above structure rarely changes, it changes only when we add new tables, ending in _tmp, and also having a column "xid". So the aim here is to speed up this query. I could materialize the result in some table, that i would refresh over night via cron, i was just wandering if there was some better way. I already made the function STABLE with no performance gain. I was also wondering if i could trick postgresql to think that the output is always the same by making it IMMUTABLE, but this also gave no performance gain. So, is there anything i could do, besides overnight materialization? Thanx. -- Achilleas Mantzios -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql