Re:

From: Дмитрий Воронин <carriingfate92(at)yandex(dot)ru>
To: Steve Midgley <science(at)misuse(dot)org>
Cc: "pgsql-sql(at)lists(dot)postgresql(dot)org" <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re:
Date: 2022-02-02 05:38:18
Message-ID: 18223021643779668@sas8-ed615920eca2.qloud-c.yandex.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi, Steve.<br /><br />19:15, 1 февраля 2022 г., Steve Midgley &lt;science(at)misuse(dot)org&gt;:<br /><blockquote class="210e7a848e8fcb45wmi-quote"><div dir="ltr"><div class="f13ca48719c8a60033905b23b39675agmail_quote"><div class="334d7d341e3233c5b27ca91297445127gmail_attr" dir="ltr">On Tue, Feb 1, 2022 at 12:42 AM Дмитрий Воронин &lt;<a href="mailto:carriingfate92(at)yandex(dot)ru">carriingfate92(at)yandex(dot)ru</a>&gt; wrote:<br /></div><blockquote class="f13ca48719c8a60033905b23b39675agmail_quote" style="border-left-color:rgb( 204 , 204 , 204 );border-left-style:solid;border-left-width:1px;margin:0px 0px 0px 0.8ex;padding-left:1ex"><div>Hi all,</div><div> </div><div>I'm using PostgreSQL 13.</div><div> </div><div>I have a table:</div><div> </div><div>CREATE TABLE test(docid integer, jsonb attrs);</div><div> </div><div>So, attrs contains data like</div><div> </div><div>...</div><div>"dates": ["<span class="1f1ea193f6735cf0wmi-callto">2019-10-02</span>", "<span class="1f1ea193f6735cf0wmi-callto">2018-02-03</span>"]</div><div>...</div><div> </div><div>So, I want to SELECT all docids, which dates in range:</div><div> </div><div><div>SELECT attrs FROM document_resinfo WHERE attrs @? '$.dates[*].datetime() ? (@ &gt;= "<span class="1f1ea193f6735cf0wmi-callto">2020-10-02</span>".datetime())';</div><div> </div><div>How can I create index on attrs field to query docids with other date? Thanks.</div></div><div> </div></blockquote><div><br /></div><div>Have you tried just putting a default index on that column? I think it should work fine.</div><div><br /></div><div>CREATE INDEX attrs_idx ON test (attrs)</div></div></div></blockquote><div><br /></div><div>Yes, I do. This speeds up search on first-levels keys on queries like:</div><div><br /></div><div>SELECT docid FROM test WHERE attrs @&gt; '{"kw": ["a", "b"]}'</div><br /><blockquote class="210e7a848e8fcb45wmi-quote"><div dir="ltr"><div class="f13ca48719c8a60033905b23b39675agmail_quote"><div>IIRC, jsonb can be indexed like any other column and you get significant performance benefits when using the index. Also IIRC, you can index "deeper" into jsonb if you only want to index part of the jsonb structure - which is more efficient, so you don't index a bunch of elements that you never search.</div></div></div></blockquote><div><br /></div>Yes, I known that.<br /><blockquote class="210e7a848e8fcb45wmi-quote"><div dir="ltr"><div class="f13ca48719c8a60033905b23b39675agmail_quote"><div></div><div>Have you tried this approach? What problems are you experiencing?</div><div></div></div></div></blockquote><div><br /></div><div>Yes, I already create another index on dates key. I think because jsonpath type does not have good index support, I will give sequential scan on this table. </div><div><br /></div><div>So, searching on dates field will be often and I want speed up by indexing but I don't known how.</div><br /><blockquote class="210e7a848e8fcb45wmi-quote"><div dir="ltr"><div class="f13ca48719c8a60033905b23b39675agmail_quote"><div>Steve</div></div></div>
</blockquote><br /><br />Best regards, Dmitry Voronin

Attachment Content-Type Size
unknown_filename text/html 3.0 KB

In response to

  • Re: at 2022-02-01 16:15:40 from Steve Midgley

Responses

  • Re: at 2022-02-02 05:47:11 from David G. Johnston

Browse pgsql-sql by date

  From Date Subject
Next Message David G. Johnston 2022-02-02 05:47:11 Re:
Previous Message Michael Lewis 2022-02-01 20:10:53 Re: