Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMSzI-00016o-Py for pgsql-performance@arkaria.postgresql.org; Wed, 06 Dec 2017 06:15:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMSzI-00076d-3P for pgsql-performance@arkaria.postgresql.org; Wed, 06 Dec 2017 06:15:20 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eMSzH-000760-Pb for pgsql-performance@lists.postgresql.org; Wed, 06 Dec 2017 06:15:19 +0000 Received: from master.mhcomputing.net ([2607:f1c0:810:6500::1] helo=mail.mhcomputing.net) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eMSzE-00061H-Nz for pgsql-performance@lists.postgresql.org; Wed, 06 Dec 2017 06:15:18 +0000 Received: from [IPv6:2001:470:3d:201:259f:192e:3701:8257] (unknown [IPv6:2001:470:3d:201:259f:192e:3701:8257]) by mail.mhcomputing.net (Postfix) with ESMTPSA id 1834811F; Tue, 5 Dec 2017 22:15:13 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: insert and query performance on big string table with pg_trgm From: Matthew Hall In-Reply-To: <56B84857-06EA-4534-A13F-F7AA3B924446@mhcomputing.net> Date: Tue, 5 Dec 2017 22:15:13 -0800 Cc: pgsql-performance@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <351E3FBB-7DFC-4BB0-841E-E7AB16DD57A3@mhcomputing.net> References: <56B84857-06EA-4534-A13F-F7AA3B924446@mhcomputing.net> To: Jeff Janes , surrano@gmail.com X-Mailer: Apple Mail (2.3124) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Nov 21, 2017, at 12:05 AM, Matthew Hall = wrote: >> Do you really need the artificial primary key, when you already have = another column that would be used as the primary key? If you need to = use this it a foreign key in another type, then very well might. But = maintaining two unique indexes doesn't come free. >=20 > OK, fair enough, I'll test with it removed and see what happens. With the integer primary key removed, it still takes ~9 hours to load = the table, so it didn't seem to make a big difference. > Fixed it; I will re-test w/ 1 GB. Have you got any recommended values = so I don't screw it up? I also took this step for maintenance_work_mem. Queries on the table still take a long time with the PK removed: # explain (analyze, buffers) select * from huge_table where value ilike = '%yahoo%'; Bitmap Heap Scan on huge_table (cost=3D593.72..68828.97 rows=3D18803 = width=3D25) (actual time=3D3224.100..70059.839 rows=3D20909 loops=3D1) Recheck Cond: ((value)::text ~~* '%yahoo%'::text) Rows Removed by Index Recheck: 17 Heap Blocks: exact=3D6682 Buffers: shared hit=3D544 read=3D6760 dirtied=3D4034 I/O Timings: read=3D69709.611 -> Bitmap Index Scan on huge_table_value_trgm_idx = (cost=3D0.00..589.02 rows=3D18803 width=3D0) (actual = time=3D3216.545..3216.545 rows=3D20926 loops=3D1) Index Cond: ((value)::text ~~* '%yahoo%'::text) Buffers: shared hit=3D352 read=3D270 I/O Timings: read=3D3171.872 Planning time: 0.283 ms Execution time: 70065.157 ms (12 rows) The slow process during inserts is: postgres: username dbname [local] INSERT The slow statement example is: 2017-12-06 04:27:11 UTC [16085-10378] username@dbname LOG: duration: = 5028.190 ms plan: Query Text: INSERT INTO huge_table (value) VALUES .... 5000 values at once ... ON CONFLICT (value) DO NOTHING Insert on huge_table (cost=3D0.00..75.00 rows=3D5000 width=3D40) Conflict Resolution: NOTHING Conflict Arbiter Indexes: huge_table_value_idx -> Values Scan on "*VALUES*" (cost=3D0.00..75.00 rows=3D5000 = width=3D40) > What is the size of the table and the gin index? The table is 10 GB. The gin index is 5.8 GB. > [=46rom Gabor Szucs] [H]ow about adding a hash value column and = creating the unique index on that one? May block some false duplicates = but the unique index would be way smaller, speeding up inserts. The mean length of the input items is about 18 bytes. The max length of = the input items is about 67 bytes. The size of the md5 would of course = be 16 bytes. I'm testing it now, and I'll write another update. Matthew.=