From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Martin Foster <martin@ethereal-realms.org>
Cc: PostgreSQL Performance <pgsql-performance@postgresql.org>
Subject: Re: Efficiency of timestamps
Date: Tue, 8 Jul 2003 17:55:51 -0700 (PDT)
Message-ID: <20030708174923.X4603-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <3F0B6178.2020805@ethereal-realms.org>
On Tue, 8 Jul 2003, Martin Foster wrote:
> As I keep looking through code to see where I can make things more
> efficient, I noticed that in some cases timestamps seem horribly
> inefficient. This leads to very long run times for certain queries.
>
> Here is an example:
>
> -- USING TIMESTAMPS TO NARROW DOWN --
>
> SELECT
> Post.PostIDNumber,
> Post.PuppeteerLogin,
> Post.PuppetName,
> Post.PostCmd,
> Post.PostClass
> FROM ethereal.Post
> WHERE Post.PostTimeStamp > (LOCALTIMESTAMP - INTERVAL '10 Minutes')
> AND Post.RealmName='Amalgam'
> AND (Post.PostTo='all' OR Post.PostTo='root')
> AND (NOT EXISTS (SELECT PuppetIgnore.PuppetLogin
> FROM ethereal.PuppetIgnore
> WHERE PuppetIgnore.PuppetIgnore='global'
> AND PuppetIgnore.PuppeteerLogin='root'
> AND PuppetIgnore.PuppetLogin=Post.PuppeteerLogin)
> OR Post.PuppeteerLogin IS NULL)
> AND (NOT EXISTS (SELECT PuppetIgnore.PuppetName
> FROM ethereal.PuppetIgnore
> WHERE PuppetIgnore='single'
> AND PuppetIgnore.PuppeteerLogin='root'
> AND PuppetIgnore.PuppetName=Post.PuppetName)
> OR Post.PuppetName IS NULL)
> ORDER BY Post.PostIDNumber LIMIT 100
>
> -- Explain of Above--
> Limit (cost=0.00..260237.32 rows=100 width=48)
> -> Index Scan using pkpost on post (cost=0.00..3020594.00 rows=1161
> width=48)
> Filter: ((posttimestamp > (('now'::text)::timestamp(6) without
> time zone - '00:10'::interval)) AND (realmname = 'Amalgam'::character
> varying) AND ((postto = 'all'::character varying) OR (postto =
> 'root'::character varying)) AND ((NOT (subplan)) OR (puppeteerlogin IS
> NULL)) AND ((NOT (subplan)) OR (puppetname IS NULL)))
I think you might get better results with some kind of multi-column index.
It's using the index to avoid a sort it looks like, but it's not helping
to find the conditions. I can't remember the correct ordering, but maybe
(posttimestamp, realmname, postidnumber). Having separate indexes on the
fields won't help currently since only one index will get chosen for the
scan. Also, what does explain analyze show?
> -- NAME : Post
> -- REFERENCES : Realm*
> -- Puppet*
> -- PuppeteerLogin*
> --
> -- DESCRIPTION : Post is the hive of activity for all realms.
> Associated with all three
> -- major tables, it is not actually linked because of the
> nature of storing
> -- posts for statistics and auditing.
>
> CREATE TABLE ethereal.Post (
> PostIDNumber INT NOT NULL DEFAULT
> NEXTVAL('ethereal.seqPost'),
> RealmName VARCHAR(30) NOT NULL,
> PuppetName VARCHAR(30),
> PuppeteerLogin VARCHAR(10),
> PostTo VARCHAR(30),
> PostTimestamp TIMESTAMP NOT NULL DEFAULT LOCALTIMESTAMP,
> PostClass VARCHAR(10) NOT NULL DEFAULT 'general',
> PostCmd VARCHAR(10) NOT NULL DEFAULT 'none',
> PostFullFormat TEXT,
> PostImagelessFormat TEXT,
> PostPartialFormat TEXT,
> CONSTRAINT pkPost PRIMARY KEY (PostIDNumber),
> CONSTRAINT enumPostClass CHECK (PostCLass IN
> ('banner','dice','duplicate','general','play','private','special','system')),
> CONSTRAINT enumPostCmd CHECK (PostCmd IN
> ('general','none','play','stream'))
> ) WITHOUT OIDS;
>
> -- STANDARD INDEX
> CREATE INDEX idxPost_Class ON ethereal.Post
> (
> PostClass
> );
>
> CREATE INDEX idxPost_Login ON ethereal.Post
> (
> PuppeteerLogin
> );
>
> CREATE INDEX idxPost_Puppet ON ethereal.Post
> (
> PuppetName
> );
>
> CREATE INDEX idxPost_Realm ON ethereal.Post
> (
> RealmName
> );
>
> CREATE INDEX idxPost_Timestamp ON ethereal.Post
> (
> PostTimestamp
> );
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: sszabo@megazone23.bigpanda.com, martin@ethereal-realms.org
Subject: Re: Efficiency of timestamps
In-Reply-To: <20030708174923.X4603-100000@megazone23.bigpanda.com>
References: <3F0B6178.2020805@ethereal-realms.org> <20030708174923.X4603-100000@megazone23.bigpanda.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox