Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1csflP-0000hd-HV for pgsql-performance@arkaria.postgresql.org; Tue, 28 Mar 2017 01:17:35 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1csflO-0007BR-W0 for pgsql-performance@arkaria.postgresql.org; Tue, 28 Mar 2017 01:17:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1csflN-00077k-SI for pgsql-performance@postgresql.org; Tue, 28 Mar 2017 01:17:33 +0000 Received: from outgoing3.cpt4.host-h.net ([197.189.247.36]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1csflJ-0007VY-3D for pgsql-performance@postgresql.org; Tue, 28 Mar 2017 01:17:33 +0000 Received: from www20.cpt1.host-h.net ([197.221.2.20]) by antispam2-cpt4.host-h.net with esmtpsa (TLSv1.2:AES128-SHA:128) (Exim 4.86) (envelope-from ) id 1csflC-000294-Bh; Tue, 28 Mar 2017 03:17:26 +0200 Received: from 196-210-206-12.dynamic.isadsl.co.za ([196.210.206.12] helo=DMZHOST) by www20.cpt1.host-h.net with esmtpa (Exim 4.80) (envelope-from ) id 1csflB-00037i-JB; Tue, 28 Mar 2017 03:17:21 +0200 Received: from Win8Dev (Unknown [10.0.0.41]) by DMZHOST with ESMTPA ; Tue, 28 Mar 2017 03:17:12 +0200 From: "Riaan Stander" To: "'Claudio Freire'" Cc: "'postgres performance list'" References: <04c401d2a753$f4b78e00$de26aa00$@exa.co.za> In-Reply-To: Subject: Re: Best design for performance Date: Tue, 28 Mar 2017 03:17:11 +0200 Message-ID: <052b01d2a761$06e8c4b0$14ba4e10$@exa.co.za> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQJD5jzhAFrFpB1c7B6a7EP3R20pYAEwBEoEoL1yqrA= Content-Language: en-za X-Authenticated-Sender: smtprelay@exa.co.za X-Virus-Scanned: Clear (ClamAV 0.99.2/23243/Mon Mar 27 22:35:03 2017) X-Originating-IP: 197.221.2.20 X-SpamExperts-Domain: exa.co.za X-SpamExperts-Username: Authentication-Results: host-h.net; auth=pass (login) smtp.auth=@exa.co.za X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.15) X-Recommended-Action: accept X-Filter-ID: s0sct1PQhAABKnZB5plbIWL5vMUYxb2kq1uspbfEA9+ihNzEqHRR3fXVWQ7SEawUiwQzKw+6v3Ca IMG6s7LqJJlV3j2ipgsAbbE1JvuwkkgZ4m00l3uPRdWwNfw+Po+GO76XSTAwtV4mg4i2ouCDa4AU hvIWAV5xUW/+gAh4vXogYoaQEuOhbu3jOwJatM0GRcOb18WfxGyg6Om6u4YYm6cYe5Akv4dhN4Vo NDTXJCGMytmwoSOAsUiZHL4elTOeW/T3iEdLQrEzANTH1RO+ZuWBOXp8nHKe0R+FkIqN7hlBaLCK i/3d82ndyQckqlk5z3irZHx8XwBM/aZ+josQAfUf9oDBqtClgM5jH/om1Q4tH6VyaEKKyFb3KuYS PtYeOngwKsK/v8O00LnH1NcGs0PkGda5olUXOJzJbtkypWIEPaEM6Ls9T603i0+693PcSkbPnLEv rPbKYugEgvhgLzYYB0K6DpInazve5ezQP+U2yPRk3H1E4ANRdN1BlPI5rJaWDcne6cToXniqtJYh 2fh2wfAJPI99az2gqFCIIfZ1+KzU7SnoXsKZpOw3kjuy3dvVP/kn/fqQjwto0FIhGpaGzcj+Mc5i sodBI9N2YC5aCjuBDzdB/sn9JnExigkZNff1J0V4Egf9XlsVRD9nnuidX4Ts4xdG+C13IyWeZaLD jVeW0gakOFUvWxP6t4hdlMG5FAt3n0MV9PNVLuAh0Zhd4C1L6tKS9QeNl4z5M3G5X3u97YLfFuPW aicDtNrQuCQdZLNhLwRrtF5z+7s1/t/VIeLbUrGXPGnBDeG6QE5dxmxbQeSW+3UskAMAiSjG2Dln t7siTDaTWkrdBlmN/9MSYGtMidsxNmAkIQaTL7UCvAsEMo1iDV1NUe8ZIjzfLQvcG12RdkTrvKAh 4k6kKQ== X-Report-Abuse-To: spam@antispammaster.host-h.net X-Pg-Spam-Score: -5.4 (-----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org I'm using the first query from here. https://wiki.postgresql.org/wiki/Disk_Usage It does seem to include toast data. The plan is to do the rights checking in the application. The join solution= gets used for reports to filter data & client adhoc queries. -----Original Message----- From: Claudio Freire [mailto:klaussfreire@gmail.com]=20 Sent: 28 March 2017 02:42 AM To: Riaan Stander Cc: postgres performance list Subject: Re: [PERFORM] Best design for performance On Mon, Mar 27, 2017 at 8:43 PM, Riaan Stander wrote: > In Postgres I was thinking of going with a design like this > > 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); > > > > This drastically cut down on the number of records in the table. It=20 > also seems to make a massive change to the storage requirements. > > The old design requires 61GB vs 2.6GB. 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. > My one concern is regarding the limitations of the array type in Postgres. > Is there a point at which one should not use it? Currently our largest=20 > client has 6000+ sites, meaning that the array would contain that many=20 > items. What would the upper feasible limit be in Postgres? In that design, rows with a large number of sites would probably end up TOA= STing the sites array. That will make access to that array a tad slower, but it would probably be = OK for your use case, since you'll ever just read one such row per query. Y= ou'll have to test to be sure. The limit on that design is about 128M items on sites, IIRC (ie: the maximu= m size of values is 1GB, so an array of 128M bigints is above that limit). = You'll probably have issues much earlier than that. For instance, a filter = of the form "site_id =3D ANY(sites)" with that many entries would probably = be unusably slow. Personally, I would go for fetching the sites array on the application side= , and using site_id =3D ANY(ARRAY[...]) if small enough, and a subselect if= the array is too big. That would let the planner be smarter, since it'll h= ave the literal array list at planning time and will be able to fetch accur= ate stats, and choose an optimal plan based on data skew. --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance