Re: [GENERAL] Efficient sorting the results of a join, without denormalization

2015-06-01 Thread Francisco Olarte
Hi Glen: On Mon, Jun 1, 2015 at 1:16 AM, Glen M. Witherington wrote: > Thanks Francisco, that makes sense. I've started moving my code to that, > and it eliminates all the performance issues I had. Happty to hear it. Seems you have a kind of speed-size trade off. If you can solve it while prese

Re: [GENERAL] Efficient sorting the results of a join, without denormalization

2015-05-31 Thread Glen M. Witherington
On Sun, May 31, 2015, at 01:16 PM, Francisco Olarte wrote: > > It may seem, and be, unideal from a redundancy perspective, but keys > are more natural. It means you have user (Glen), folder (Glen, PGlist) > and message (Glen,PGlist,27), different from (Glen,Inbox,27) or (Glen, > PgList,28) or (

Re: [GENERAL] Efficient sorting the results of a join, without denormalization

2015-05-31 Thread Bill Moran
On Sun, 31 May 2015 04:50:00 -0500 "Glen M. Witherington" wrote: > > On Sun, May 31, 2015, at 12:53 AM, Tom Lane wrote: > > "Glen M. Witherington" writes: > > > And here's the query I want to do, efficiently: > > > > > SELECT * FROM c > > > JOIN b ON b.id = c.b_id > > > JOIN a ON a.id = b.a

Re: [GENERAL] Efficient sorting the results of a join, without denormalization

2015-05-31 Thread Francisco Olarte
Hi Glen: On Sun, May 31, 2015 at 6:43 AM, Glen M. Witherington wrote: > On Sat, May 30, 2015, at 11:33 PM, David G. Johnston wrote: >> This is one problem with using made up surrogate keys... >> The PK of A is a component of both the PK of B and the PK of C but you throw >> that information away

Re: [GENERAL] Efficient sorting the results of a join, without denormalization

2015-05-31 Thread Glen M. Witherington
On Sun, May 31, 2015, at 12:53 AM, Tom Lane wrote: > "Glen M. Witherington" writes: > > And here's the query I want to do, efficiently: > > > SELECT * FROM c > > JOIN b ON b.id = c.b_id > > JOIN a ON a.id = b.a_id > > WHERE a.id = 3 > > ORDER BY b.created_at DESC > > LIMIT 10 > > At least

Re: [GENERAL] Efficient sorting the results of a join, without denormalization

2015-05-30 Thread Tom Lane
"Glen M. Witherington" writes: > And here's the query I want to do, efficiently: > SELECT * FROM c > JOIN b ON b.id = c.b_id > JOIN a ON a.id = b.a_id > WHERE a.id = 3 > ORDER BY b.created_at DESC > LIMIT 10 At least for that dummy data, this seems sufficient: regression=# create index on b

Re: [GENERAL] Efficient sorting the results of a join, without denormalization

2015-05-30 Thread Glen M. Witherington
On Sat, May 30, 2015, at 11:33 PM, David G. Johnston wrote: > This is one problem with using made up surrogate keys... > > The PK of A is a component of both the PK of B and the PK of C but you throw > that information away by using serial fields for PKs instead.  You should > have unique ind

Re: [GENERAL] Efficient sorting the results of a join, without denormalization

2015-05-30 Thread David G. Johnston
On Saturday, May 30, 2015, Glen M. Witherington wrote: > Sorry about the horrendous subject, let me explain by example: > > Let's take this schema: > > > ``` > CREATE TABLE a ( > id bigserial PRIMARY KEY, > created_at timestamp with time zone NOT NULL DEFAULT NOW() > ); > > CREATE TABLE b(

[GENERAL] Efficient sorting the results of a join, without denormalization

2015-05-30 Thread Glen M. Witherington
Sorry about the horrendous subject, let me explain by example: Let's take this schema: ``` CREATE TABLE a ( id bigserial PRIMARY KEY, created_at timestamp with time zone NOT NULL DEFAULT NOW() ); CREATE TABLE b( id bigserial PRIMARY KEY, a_id bigint NOT NULL REFERENCES a(id), create