pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feeddata model one large and many small columns
5+ messages / 4 participants
[nested] [flat]
* data model one large and many small columns
@ 2016-07-26 20:22 Campbell, Lance <lance@illinois.edu>
0 siblings, 3 replies; 5+ messages in thread
From: Campbell, Lance @ 2016-07-26 20:22 UTC (permalink / raw)
To: pgsql-admin
PostgreSQL 9.5.3
Suppose you have a table that consists of a lot of small sized columns with one really large text column. The text column represents an average sized web page. When inserting or updating you will work with only one row at a time.
When selecting information you will either:
A) select all columns in one row for display or editing purposes.
B) Or you will select hundreds of rows but NOT the very large text column.
Question: Is there any performance to be gained from PostgreSQL by storing the data as two tables versus one table? In the two table model you would put the large column in a secondary table with a foreign key back to the primary table. So each table would have a one to one relationship. In the two table model when you need a single record with everything you would select from both tables based on a key. When selecting hundreds of rows at one time you would only select from the primary table.
I know there is this concept of TOAST. I don't know if it even matters to PostgreSQL if I had two separate tables or just one.
Thanks for your insight.
Lance
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: data model one large and many small columns
@ 2016-07-26 21:00 Scott Whitney <scott@journyx.com>
parent: Campbell, Lance <lance@illinois.edu>
2 siblings, 0 replies; 5+ messages in thread
From: Scott Whitney @ 2016-07-26 21:00 UTC (permalink / raw)
To: Campbell, Lance <lance@illinois.edu>; pgsql-admin
My immediate response is that if you know at the time you build the query and exclude the BLOB/text, it _should_ be immaterial, but inserts might suffer in and single table based on indexes.
Discussion?
-------- Original message --------
From: "Campbell, Lance" <lance@illinois.edu>
Date: 07/26/2016 3:24 PM (GMT-06:00)
To: pgsql-admin@postgresql.org
Subject: [ADMIN] data model one large and many small columns
PostgreSQL 9.5.3
Suppose you have a table that consists of a lot of small sized columns with one really large text column. The text column represents an average sized web page. When inserting or updating you will work with only one row at a time.
When selecting information you will either:
A) select all columns in one row for display or editing purposes.
B) Or you will select hundreds of rows but NOT the very large text column.
Question: Is there any performance to be gained from PostgreSQL by storing the data as two tables versus one table? In the two table model you would put the large column in a secondary table with a foreign key back to the primary table. So each table would have a one to one relationship. In the two table model when you need a single record with everything you would select from both tables based on a key. When selecting hundreds of rows at one time you would only select from the primary table.
I know there is this concept of TOAST. I don't know if it even matters to PostgreSQL if I had two separate tables or just one.
Thanks for your insight.
Lance
Journyx, Inc.
7600 Burnet Road #300
Austin, TX 78757
www.journyx.com
p 512.834.8888
f 512-834-8858
Do you receive our promotional emails? You can subscribe or unsubscribe to those emails at http://go.journyx.com/emailPreference/e/4932/714/
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: data model one large and many small columns
@ 2016-07-26 21:17 David G. Johnston <david.g.johnston@gmail.com>
parent: Campbell, Lance <lance@illinois.edu>
2 siblings, 0 replies; 5+ messages in thread
From: David G. Johnston @ 2016-07-26 21:17 UTC (permalink / raw)
To: Campbell, Lance <lance@illinois.edu>; +Cc: pgsql-admin
On Tue, Jul 26, 2016 at 4:22 PM, Campbell, Lance <lance@illinois.edu> wrote:
> Is there any performance to be gained from PostgreSQL by storing the data
> as two tables versus one table?
>
​PostgreSQL already does this for you via the TOAST mechanism you mentioned.
https://www.postgresql.org/docs/9.6/static/storage-toast.html
David J.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: data model one large and many small columns
@ 2016-07-26 21:18 Tom Lane <tgl@sss.pgh.pa.us>
parent: Campbell, Lance <lance@illinois.edu>
2 siblings, 1 reply; 5+ messages in thread
From: Tom Lane @ 2016-07-26 21:18 UTC (permalink / raw)
To: Campbell, Lance <lance@illinois.edu>; +Cc: pgsql-admin
"Campbell, Lance" <lance@illinois.edu> writes:
> Suppose you have a table that consists of a lot of small sized columns with one really large text column. The text column represents an average sized web page. When inserting or updating you will work with only one row at a time.
> When selecting information you will either:
> A) select all columns in one row for display or editing purposes.
> B) Or you will select hundreds of rows but NOT the very large text column.
> Question: Is there any performance to be gained from PostgreSQL by
> storing the data as two tables versus one table?
No, probably not; TOAST will effectively do that for you by off-loading
the large text values into the side table.
If you were to do an explicit join, there would be some use-cases ---
mainly where you were selecting a LOT of rows --- where in theory you
could get a smarter plan from the explicit join. TOAST will effectively
always fetch the text values via a nestloop-with-inner-indexscan plan,
but maybe hashing or merging would be smarter. Unfortunately, with two
explicit tables, TOAST would still apply to the second table, which means
that what you've really got under the hood is a three-way join, with the
intermediate table contributing nothing except overhead.
So don't bother ...
regards, tom lane
--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: data model one large and many small columns
@ 2016-07-26 21:24 Campbell, Lance <lance@illinois.edu>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 5+ messages in thread
From: Campbell, Lance @ 2016-07-26 21:24 UTC (permalink / raw)
To: 'Tom Lane' <tgl@sss.pgh.pa.us>; +Cc: pgsql-admin
I had a hunch this was the case. I just wanted to double check.
Lance
-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Tuesday, July 26, 2016 4:18 PM
To: Campbell, Lance <lance@illinois.edu>
Cc: pgsql-admin@postgresql.org
Subject: Re: [ADMIN] data model one large and many small columns
"Campbell, Lance" <lance@illinois.edu> writes:
> Suppose you have a table that consists of a lot of small sized columns with one really large text column. The text column represents an average sized web page. When inserting or updating you will work with only one row at a time.
> When selecting information you will either:
> A) select all columns in one row for display or editing purposes.
> B) Or you will select hundreds of rows but NOT the very large text column.
> Question: Is there any performance to be gained from PostgreSQL by
> storing the data as two tables versus one table?
No, probably not; TOAST will effectively do that for you by off-loading the large text values into the side table.
If you were to do an explicit join, there would be some use-cases --- mainly where you were selecting a LOT of rows --- where in theory you could get a smarter plan from the explicit join. TOAST will effectively always fetch the text values via a nestloop-with-inner-indexscan plan, but maybe hashing or merging would be smarter. Unfortunately, with two explicit tables, TOAST would still apply to the second table, which means that what you've really got under the hood is a three-way join, with the intermediate table contributing nothing except overhead.
So don't bother ...
regards, tom lane
--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2016-07-26 21:24 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-07-26 20:22 data model one large and many small columns Campbell, Lance <lance@illinois.edu>
2016-07-26 21:00 ` Scott Whitney <scott@journyx.com>
2016-07-26 21:17 ` David G. Johnston <david.g.johnston@gmail.com>
2016-07-26 21:18 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-07-26 21:24 ` Campbell, Lance <lance@illinois.edu>
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