Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id E136A63416A for ; Fri, 5 Feb 2010 11:10:02 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 90974-07-4 for ; Fri, 5 Feb 2010 15:09:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ew0-f222.google.com (mail-ew0-f222.google.com [209.85.219.222]) by mail.postgresql.org (Postfix) with ESMTP id EE1C8633CA5 for ; Fri, 5 Feb 2010 11:08:50 -0400 (AST) Received: by ewy22 with SMTP id 22so860592ewy.34 for ; Fri, 05 Feb 2010 07:08:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:cc:content-type; bh=WMOlxFKZLEKgJmo1q85/1n+S4PdV/ffqBXWh/f75Hhs=; b=nnwnlPTAqtgqTFxmG9SXk5VU/SgoJTkm1F4MsbrcOfGhSDFJPmiMfg4Ea5eYmmn3Lw 1MKUGq9C4DBbzLrZ/TyUmbky/onEqsgothy1cVlaAzonln5uRvD+eSZI9jCZ74a8q0qI 9bFG9MK289ps1l2Fk+YqWERQ00zzbPLBm0758= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=j5ygXviAJFUjBWAzrLSgBzVXYRoUa5Hu62weZEWk6Om40mNkuNz6jYElHIDBHQwrXF BvDYQWpt11tjoohIgNpzizVFdbNAPXIO0bs0nzOrigNemamm3OzpJ4eJjbGxbBpU1kLf nG4/bDMy9/7qBsq1wizbpr86vSlg4gePRKxiA= MIME-Version: 1.0 Received: by 10.216.85.133 with SMTP id u5mr1524987wee.91.1265382528609; Fri, 05 Feb 2010 07:08:48 -0800 (PST) In-Reply-To: <15213497474b6c0fe595df07.79488231.Active.mail@starapoczta.nazwa.pl> References: <15213497474b6c0fe595df07.79488231.Active.mail@starapoczta.nazwa.pl> From: Nikolas Everett Date: Fri, 5 Feb 2010 10:08:28 -0500 Message-ID: Subject: Re: index on partitioned table To: Wojtek Cc: pgsql-performance@postgresql.org Content-Type: multipart/alternative; boundary=0016e6d63fff1f6fcf047edbd430 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.395 tagged_above=-10 required=5 tests=AWL=0.047, BAYES_00=-2.599, HTML_MESSAGE=0.001, SUBJECT_FUZZY_TION=0.156 X-Spam-Level: X-Archive-Number: 201002/101 X-Sequence-Number: 37522 --0016e6d63fff1f6fcf047edbd430 Content-Type: text/plain; charset=ISO-8859-1 2010/2/5 Wojtek > > partitions are will typically have from 200k to 300k rows, i have 52 > partitions per year and I'm keeping around 4-5 years of history. However, > they will query last 3-4 months most often. > Do you mean 12 partitions a year or weekly partitions? > Most of my queries will have where conditions on timedate and > sys_device_id, but a lot of them will have additional clause: where > usefields is not null. Some of the queries will be limited on timedate only. > > I'm trying to figure out the best indexing strategy for this table. If a > query will have condition on sys_device_id and/or usefields is not null, > postgres won't use my index. > I've experimented turning on and off enable_seqscan and creating different > indexes and so far btree index on (usefields, sys_device_id, timedate) turn > out to be the best. > If I create btree index only on (usefields, timedate) or (sys_device_id, > timedate), planner will go for seqscan. If I turn off seqscan, postgres will > use index but performance will be worse than seqscan. > > > My question finally: is btree index on (usefields, sys_device_id, timedate) > really the best choice? I'm yet to examine options of creating separate > indexes for timedate, usefields and sys_device_id. Possibly I should try > using GiST or GIN? > I'd start with no indexes and then add indexes as your queries start to take too long. I'd start with single column indexes. PostgreSQL is perfectly capable of bitmap anding the indexes if it has to. Multicolumn indexes are the last place I'd go. I'm not sure you'll need an index on timedate. It depends on the length of the timedate segments you'll be querying. If they are typically a month long then you shouldn't have an index on it at all. Even if they are a week long its probably not worth it. My guess is that an index sys_device_id will be selective enough for most of what you need. What does PostgreSQL tell you about the statistics of that column? > Regards, > foo Regards, bar --0016e6d63fff1f6fcf047edbd430 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

2010/2/5 Wojtek <foo@twine.pl>
partitions are will typically have from 200k to 300k rows, i have 52 partit= ions per year and I'm keeping around 4-5 years of history. However, the= y will query last 3-4 months most often.
Do you mean 1= 2 partitions a year or weekly partitions?
=A0
Most of my queries will have where conditions on timedate and sys_device_id= , but a lot of them will have additional clause: where usefields is not nul= l. Some of the queries will be limited on timedate only.

I'm trying to figure out the best indexing strategy for this table. If = a query will have condition on sys_device_id and/or usefields is not null, = postgres won't use my index.
I've experimented turning on and off enable_seqscan and creating differ= ent indexes and so far btree index on (usefields, sys_device_id, timedate) = turn out to be the best.
If I create btree index only on (usefields, timedate) or (sys_device_id, ti= medate), planner will go for seqscan. If I turn off seqscan, postgres will = use index but performance will be worse than seqscan.


My question finally: is btree index on (usefields, sys_device_id, timedate)= really the best choice? I'm yet to examine options of creating separat= e indexes for timedate, usefields and sys_device_id. Possibly I should try = using GiST or GIN?

I'd start with no indexes and then add= indexes as your queries start to take too long. =A0I'd start with sing= le column indexes. =A0PostgreSQL is perfectly capable of bitmap anding the = indexes if it has to. =A0Multicolumn indexes are the last place I'd go.=

I'm not sure you'll need an index on timedate. = =A0It depends on the length of the timedate segments you'll be querying= . =A0If they are typically a month long then you shouldn't have an inde= x on it at all. =A0Even if they are a week long its probably not worth it.<= /div>

My guess is that an index sys_device_id will be selecti= ve enough for most of what you need. =A0What does PostgreSQL tell you about= the statistics of that column?
=A0
Regards,
foo

Regards,
bar=A0
--0016e6d63fff1f6fcf047edbd430--