From: Riaan Stander <rstander@exa.co.za>
To: pgsql-performance@postgresql.org
Subject: Re: Best design for performance
Date: Tue, 28 Mar 2017 14:41:37 +0200
Message-ID: <113e6bde-6595-44b8-79a4-992a2eea4c27@exa.co.za> (raw)
In-Reply-To: <CAGTBQpYRjtdHi9J30vjVV1--rsq4q4UZPMj5zZ2fy032niSQaA@mail.gmail.com>
References: <04c401d2a753$f4b78e00$de26aa00$@exa.co.za>
<CAGTBQpYfdksf+moXe0Drm-f_=t8wXj0_TL_AKuSVaOa+cOq09Q@mail.gmail.com>
<052b01d2a761$06e8c4b0$14ba4e10$@exa.co.za>
<CAGTBQpYRjtdHi9J30vjVV1--rsq4q4UZPMj5zZ2fy032niSQaA@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>
On 28 Mar 2017 4:22 AM, Claudio Freire wrote:
>> From: Claudio Freire [mailto:klaussfreire@gmail.com]
>>
>> How did you query the table's size? You're probably failing to account for TOAST tables.
>>
>> I'd suggest using pg_total_relation_size.
> ...
> On Mon, Mar 27, 2017 at 10:17 PM, Riaan Stander <rstander@exa.co.za> wrote:
>> I'm using the first query from here.
>> https://wiki.postgresql.org/wiki/Disk_Usage
> Please don't top post.
>
> It's a surprisingly big difference. TOAST could be compressing the
> array, but I wouldn't expect it to be that compressible. Do you have
> any stats about the length of the site array per row?
>
>> The plan is to do the rights checking in the application. The join solution gets used for reports to filter data & client adhoc queries.
> Especially for reporting queries, you want the planner's stats to be
> as accurate as possible, and placing a literal sites arrays in the
> query in my experience is the best way to achieve that. But that is
> indeed limited to reasonably small arrays, thereby the need to have
> both variants to adapt the query to each case.
>
> If you can't afford to do that change at the application level, I
> would expect that the original schema without the array should be
> superior. The array hides useful information from the planner, and
> that *should* hurt you.
>
> You'll have to test with a reasonably large data set, resembling a
> production data set as much as possible.
>
>
I did some more testing on this. My primary concern that not all the
data was there in the array version,but after doing some extensive
testing all seems to be there.
I've done some comparisons vs the SQL Server version too.
SQL Sever Table with over 700mil records:
CREATE TABLE [dbo].[usrUserRights] (
[UserId] [dbo].[dm_Id] NOT NULL,
[SiteId] [dbo].[dm_Id] NOT NULL,
[RightId] [dbo].[dm_Id] NOT NULL,
CONSTRAINT [pk_usrUserRights_UserId_RightId_SiteId] PRIMARY KEY
CLUSTERED([UserId],[RightId],[SiteId])
);
Takes23GB for data and 200MB for indexes.
Postgres table with over 700mil records:
CREATE TABLE security.user_right_site2
(
user_id bigint NOT NULL,
right_id bigint NOT NULL,
site_id bigint NOT NULL
);
create index on security.user_right_site2(user_id, right_id);
Takes 35GB data and 26GB index, for a total of 61GB.
That is quite a large increase over SQL Server storage. Am I missing
something? Makes me worry about the rest of the database we still have
to convert.
Postgres Array version ends up with only 600k records, due to aggregation:
CREATE TABLE security.user_right_site
(
user_id bigint NOT NULL,
right_id bigint NOT NULL,
sites bigint[]
);
create index on security.user_right_site(user_id, right_id);
Takes 339Mb data, 25Mb index and 2240Mb TOAST
Regarding the Array length for each of these. They currently have max
6500 site ids.
Regards
Riaan
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: rstander@exa.co.za
Subject: Re: Best design for performance
In-Reply-To: <113e6bde-6595-44b8-79a4-992a2eea4c27@exa.co.za>
* 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