Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id B880D2DF893 for ; Tue, 13 Dec 2011 09:55:20 -0400 (AST) Received: from s1v2.e-lietuva.lt ([82.135.156.154] helo=centos5.e-lietuva.lt) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RaSpC-0003UP-Ev for pgsql-performance@postgresql.org; Tue, 13 Dec 2011 13:55:20 +0000 Received: (qmail 1594 invoked from network); 13 Dec 2011 15:55:03 +0200 Received: from ip-195-14-173-2.bnk.lt (HELO ?192.168.10.129?) (195.14.173.2) by s1v2.e-lietuva.lt with (DHE-RSA-AES256-SHA encrypted) SMTP; 13 Dec 2011 15:55:02 +0200 Message-ID: <4EE75936.8040806@ruptela.lt> Date: Tue, 13 Dec 2011 15:55:02 +0200 From: Aleksej Trofimov User-Agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111124 Thunderbird/8.0 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Postgres array parser Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201112/97 X-Sequence-Number: 45896 Hello, I wanted to ask according such a problem which we had faced with. We are widely using postgres arrays like key->value array by doing like this: {{1,5},{2,6},{3,7}} where 1,2,3 are keys, and 5,6,7 are values. In our pgSql functions we are using self written array_input(array::numeric[], key::numeric) function which makes a loop on whole array and searches for key like FOR i IN 1 .. size LOOP if array[i][1] = key then return array[i][2]; end if; END LOOP; But this was a good solution until our arrays and database had grown. So now FOR loop takes a lot of time to find value of an array. And my question is, how this problem of performance could be solved? We had tried pgperl for string parsing, but it takes much more time than our current solution. Also we are thinking about self-written C++ function, may be someone had implemented this algorithm before? -- Best regards Aleksej Trofimov