Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id BF1F59FB66E for ; Wed, 7 Mar 2007 10:50:49 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 99254-06 for ; Wed, 7 Mar 2007 10:50:41 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from web63311.mail.re1.yahoo.com (web63311.mail.re1.yahoo.com [69.147.97.36]) by postgresql.org (Postfix) with SMTP id 1BAFD9FB648 for ; Wed, 7 Mar 2007 10:50:41 -0400 (AST) Received: (qmail 25584 invoked by uid 60001); 7 Mar 2007 14:50:40 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=6vc8J6omQSJZWChBq/mSkZ3pAsLk7/QLw3fLa+hjXcoWr0qOyMaG6Jvi8FWdJQVNkeo8mZNF3Liq3kK9RpjlM+YZs3WEvXCkcZEdifhL0+R7lnzDMOLFfj0QPVXpC6oGaENno/tywHoR2TEPEITDP8JDRpW3BDaWmwJLVc71uiE= ; Message-ID: <20070307145040.25582.qmail@web63311.mail.re1.yahoo.com> X-YMail-OSG: WE0w1WEVM1m08v764MMtgtECIe3R.doA2b41YxUPe3WCD3GgOX4beMWqiT22DEiGu9Ut9tJrwAgIH63sXAYIS_.iPXpGsXXCr9BaWuLXYmDpG6KgfSZNCQ-- Received: from [66.51.222.239] by web63311.mail.re1.yahoo.com via HTTP; Wed, 07 Mar 2007 06:50:40 PST Date: Wed, 7 Mar 2007 06:50:40 -0800 (PST) From: Zoolin Lin Subject: Re: Any advantage to integer vs stored date w. timestamp To: pgsql-performance@postgresql.org In-Reply-To: <45EE805F.1060708@archonet.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-109837897-1173279040=:21635" Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.568 tagged_above=0 required=5 tests=AWL, BAYES_50, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, DNS_FROM_RFC_WHOIS, HTML_MESSAGE X-Spam-Level: ** X-Archive-Number: 200703/151 X-Sequence-Number: 23556 --0-109837897-1173279040=:21635 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit thanks for your reply > Primary table is all integers like: > > date id | num1 | num2 | num3 | num4 | num5 | num6 | num7 | num 8 > ------------------------------------------------------------------------------------------------- > primary key is on date to num->6 columns >>What types are num1->8? They are all integer > date_id | date w timestamp ---------------------------------------- 1 > | 2007-2-15 Midnight 2 | 2007-2-15 1 am 3 | 2007-2-15 > 2 am etc for 24 hours each day >>If you only want things accurate to an hour, you could lost the join and >>just store it as an int: 2007021500, 2007021501 etc. Hmm yeh I could, I think with the amount of data in the db though it behooves me to use one of the date types, even if via lookup table. So I guess I'm just not sure if I'm really gaining anything by using an integer date id column and doing a join on a date lookup table, vs just making it a date w. timestamp column and having duplicate dates in that column. I would imagine internally that the date w. timestamp is stored as perhaps a time_t type plus some timezone information. I don't know if it takes that much more space, or there's a significant performance penalty in using it 2,500 rows per hour, with duplicate date columns, seems like it could add up though. thanks Richard Huxton wrote: Zoolin Lin wrote: > Hi, > > I have database with a huge amount of data so i'm trying to make it > as fast as possible and minimize space. > > One thing i've done is join on a prepopulated date lookup table to > prevent a bunch of rows with duplicate date columns. Without this I'd > have about 2500 rows per hour with the exact same date w. timestamp > in them. > > My question is, with postgres do I really gain anything by this, or > should I just use the date w. timestamp column on the primary table > and ditch the join on the date_id table. > > Primary table is all integers like: > > date id | num1 | num2 | num3 | num4 | num5 | num6 | num7 | num 8 > ------------------------------------------------------------------------------------------------- > primary key is on date to num->6 columns What types are num1->8? > date_id lookup table: > > This table is prepopulated with the date values that will be used. > > date_id | date w timestamp ---------------------------------------- 1 > | 2007-2-15 Midnight 2 | 2007-2-15 1 am 3 | 2007-2-15 > 2 am etc for 24 hours each day If you only want things accurate to an hour, you could lost the join and just store it as an int: 2007021500, 2007021501 etc. That should see you good to year 2100 or so. -- Richard Huxton Archonet Ltd ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster --------------------------------- Food fight? Enjoy some healthy debate in the Yahoo! Answers Food & Drink Q&A. --0-109837897-1173279040=:21635 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit thanks for your reply

> Primary table is all integers like:
>
> date id | num1 | num2 | num3 | num4 | num5 | num6 | num7 | num 8
> -------------------------------------------------------------------------------------------------
> primary key is on date to num->6 columns

>>What types are num1->8?

They are all integer


> date_id | date w timestamp ---------------------------------------- 1
> | 2007-2-15 Midnight 2 | 2007-2-15 1 am 3 | 2007-2-15
> 2 am etc for 24 hours each day

>>If you only want things accurate to an hour, you could lost the join and
>>just store it as an int: 2007021500, 2007021501 etc.

Hmm yeh I could, I think with the amount of data in the db though it behooves me to use one of the date types, even if via lookup table.

So I guess I'm just not sure if I'm really gaining anything by using an integer  date id column and doing a join on a date lookup table, vs just making it a date w. timestamp column and having duplicate dates in that column.

I would imagine internally that the date w. timestamp is stored as perhaps a time_t type  plus some timezone information. I don't know if it takes that much more space, or there's a significant performance penalty in using it

2,500 rows per hour, with duplicate date columns, seems like it could add up though.

thanks

Richard Huxton <dev@archonet.com> wrote:
Zoolin Lin wrote:
> Hi,
>
> I have database with a huge amount of data so i'm trying to make it
> as fast as possible and minimize space.
>
> One thing i've done is join on a prepopulated date lookup table to
> prevent a bunch of rows with duplicate date columns. Without this I'd
> have about 2500 rows per hour with the exact same date w. timestamp
> in them.
>
> My question is, with postgres do I really gain anything by this, or
> should I just use the date w. timestamp column on the primary table
> and ditch the join on the date_id table.
>
> Primary table is all integers like:
>
> date id | num1 | num2 | num3 | num4 | num5 | num6 | num7 | num 8
> -------------------------------------------------------------------------------------------------
> primary key is on date to num->6 columns

What types are num1->8?

> date_id lookup table:
>
> This table is prepopulated with the date values that will be used.
>
> date_id | date w timestamp ---------------------------------------- 1
> | 2007-2-15 Midnight 2 | 2007-2-15 1 am 3 | 2007-2-15
> 2 am etc for 24 hours each day

If you only want things accurate to an hour, you could lost the join and
just store it as an int: 2007021500, 2007021501 etc.

That should see you good to year 2100 or so.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster


Food fight? Enjoy some healthy debate
in the Yahoo! Answers Food & Drink Q&A. --0-109837897-1173279040=:21635--