Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XxmQN-0008W9-VE for pgsql-sql@arkaria.postgresql.org; Mon, 08 Dec 2014 00:43:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XxmQN-0006vv-Et for pgsql-sql@arkaria.postgresql.org; Mon, 08 Dec 2014 00:43:39 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XxmQM-0006tT-4l for pgsql-sql@postgresql.org; Mon, 08 Dec 2014 00:43:38 +0000 Received: from mail-qg0-x235.google.com ([2607:f8b0:400d:c04::235]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XxmQJ-0000IT-1D for pgsql-sql@postgresql.org; Mon, 08 Dec 2014 00:43:36 +0000 Received: by mail-qg0-f53.google.com with SMTP id q108so2827669qgd.26 for ; Sun, 07 Dec 2014 16:43:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=3d3KDAC37sp1uApJ1ZP1lhWVVeQPr0SSruONPBHym8c=; b=D8HLkKlZ2ZcHWGw6igG4NyzFKwNZRizxDUB0j5VT+w9JDDp2IDMSMRl0KOR//647xY 0qf1UxXr+O/5JBegcBM7qt/mhNkdTJeuRgVeEtOY00e3cD4/kwtUzy5ba8V2sIIgDDql O8cZ0rG3+laTL9HItuU967B6PuNprswtWomH6r2Ul5dsbzW7epm8uR+Tds9EccsWAlop sQR+IUEfM5fp/TN1TqF58HDeOcvBEZz+BFdSCntbvUyGYQgxjWYMV4IMfebYBzkJJ6Wc UAJIWRb3hI4tfgFs+8Iqjb1CUZmglLlkkLQkgQ2u3uoM2QHqyomZJv1CksJiCMuzARMg Ftqw== X-Received: by 10.140.95.225 with SMTP id i88mr45584066qge.2.1417999414424; Sun, 07 Dec 2014 16:43:34 -0800 (PST) Received: from timbomac-2.local (host247.181-15-182.telecom.net.ar. [181.15.182.247]) by mx.google.com with ESMTPSA id k6sm36498448qaz.41.2014.12.07.16.43.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 07 Dec 2014 16:43:34 -0800 (PST) Message-ID: <5484F437.2080402@gmail.com> Date: Sun, 07 Dec 2014 21:43:35 -0300 From: Tim Dudgeon User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: querying with index on jsonb slower than standard column. Why? References: <5484DBDA.6090405@gmail.com> <5484EEA7.1030403@aklaver.com> In-Reply-To: <5484EEA7.1030403@aklaver.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) 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 On 07/12/2014 21:19, Adrian Klaver wrote: > On 12/07/2014 02:59 PM, Tim Dudgeon wrote: >> I was doing some performance profiling regarding querying against jsonb >> columns and found something I can't explain. >> I created json version and standard column versions of some data, and >> indexed the json 'fields' and the normal columns and executed equivalent >> queries against both. >> I find that the json version is quite a bit (approx 3x) slower which I >> can't explain as both should (and are according to plans are) working >> against what I would expect are equivalent indexes. >> >> Can anyone explain this? > > The docs can: > > http://www.postgresql.org/docs/9.4/interactive/datatype-json.html#JSON-INDEXING > If so them I'm missing it. The index created is not a gin index. Its a standard btree index on the data extracted from the json. So the indexes on the standard columns and the ones on the 'fields' extracted from the json seem to be equivalent. But perform differently. Tim > >> >> Example code is here: >> >> >> create table json_test ( >> id SERIAL, >> assay1_ic50 FLOAT, >> assay2_ic50 FLOAT, >> data JSONB >> ); >> >> DO >> $do$ >> DECLARE >> val1 FLOAT; >> val2 FLOAT; >> BEGIN >> for i in 1..10000000 LOOP >> val1 = random() * 100; >> val2 = random() * 100; >> INSERT INTO json_test (assay1_ic50, assay2_ic50, data) VALUES >> (val1, val2, ('{"assay1_ic50": ' || val1 || ', "assay2_ic50": ' || >> val2 || ', "mod": "="}')::jsonb); >> end LOOP; >> END >> $do$ >> >> create index idx_data_json_assay1_ic50 on json_test (((data ->> >> 'assay1_ic50')::float)); >> create index idx_data_json_assay2_ic50 on json_test (((data ->> >> 'assay2_ic50')::float)); >> >> create index idx_data_col_assay1_ic50 on json_test (assay1_ic50); >> create index idx_data_col_assay2_ic50 on json_test (assay2_ic50); >> >> select count(*) from json_test; >> select * from json_test limit 10; >> >> select count(*) from json_test where (data->>'assay1_ic50')::float > 90 >> and (data->>'assay2_ic50')::float < 10; >> select count(*) from json_test where assay1_ic50 > 90 and assay2_ic50 >> < 10; >> >> >> >> Thanks >> Tim >> >> >> > > -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql