Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hnlWV-0003I4-Rb for pgsql-general@arkaria.postgresql.org; Wed, 17 Jul 2019 15:07:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hnlWU-0004UT-GF for pgsql-general@arkaria.postgresql.org; Wed, 17 Jul 2019 15:07:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hnlWU-0004UM-2r for pgsql-general@lists.postgresql.org; Wed, 17 Jul 2019 15:07:14 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1hnlWQ-0005km-HL for pgsql-general@postgresql.org; Wed, 17 Jul 2019 15:07:12 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 05F872239B; Wed, 17 Jul 2019 11:07:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 17 Jul 2019 11:07:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=p fgOVFhiZEcfkSTB6D2kg+NpmAnT4n+ZSM4Vt48kEMI=; b=ZywQLIxan5EAV+0SV b6r5sDrugZ0dgWsIeYGNoFxBaj9MZH2p0jCyot/giqv8Wqw/idsXYgchGG8ZYLKD HclPLIDZPNH0plvquizfEntdAlyeHeI0WjJTwninJyQYru7tMt91wh+8M6xXeXfT IY1jRn/wP7qzybMEgRDKUM1CHEQd4LaEPkbRPXCev8Aw8TOsIHues2vwt4KH5icL nwnR6VYIp8i/ZvSnGKPd5pSNlzuhr8npJipmuqEr+3REwCHc6ouHQVlYkz5UK5iz iRcZVtQnpfxpuIHUAUAeWAETKbxD2gFS8emT29WOpThl8uPgwOvcoBsykgDUOkcn vsSmA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=pfgOVFhiZEcfkSTB6D2kg+NpmAnT4n+ZSM4Vt48kE MI=; b=QPeTcvxzIRwcG539Fat6Y9PS/7HAVyAJSacGVRkbRm3R05RBjaT3Vopdd sxvTwkh1XFePeJJT6PzvruO0OSRwaasx7+km7QbFy1UR50voBukDPNIsb8X+wHX6 XROPOKT2j/gqWGrMzKxepsHZ90bRWX3nBj8xmnyOCijqKqt4jsIGDGuuzP40KlGg +A8ZdEwSGIiC41Fyt1IPACLcESIa3JedamsKnqUHlPE1yxIuI9A1+9Tn4nwKXi+7 JJ81JTyRzoa5xR44OIHK9BIn8XwINxSq7fIXt4YAkc2NOkTNouPR4/tbUxJ1xC9m JdUs059tEKJY8l12Rn8xZ94pNpRsA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrieefgdeiudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepuffvfhfhkffffgggjggtgfesthekre dttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhl rghvvghrsegrkhhlrghvvghrrdgtohhmqeenucffohhmrghinhepvhholhhkrghnuhhnsh grlhdrtghomhenucfkphepjedurddvuddvrdduhedtrddvtddvnecurfgrrhgrmhepmhgr ihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmnecuve hluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.4] (unknown [71.212.150.202]) by mail.messagingengine.com (Postfix) with ESMTPA id 16538380075; Wed, 17 Jul 2019 11:07:07 -0400 (EDT) Subject: Re: Removing a key from jsonb is sloooow To: Volkan Unsal References: <553286cb-47f5-bf94-42f2-12d1f489fbdf@aklaver.com> Cc: pgsql-general From: Adrian Klaver Message-ID: Date: Wed, 17 Jul 2019 08:07:07 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 7/17/19 7:59 AM, Volkan Unsal wrote: > Aha, it's due to the trigger, isn't it? Yes. > > On Wed, Jul 17, 2019 at 10:58 AM Volkan Unsal > wrote: > > @Adrian > > More information about my setup: > > Postgres version: > PostgreSQL 10.9 (Debian 10.9-1.pgdg90+1) on x86_64-pc-linux-gnu, > compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit > > Table schema: > CREATE TABLE public.projects ( >    misc jsonb DEFAULT '{}'::jsonb NOT NULL > ); > > Explain analyze: > explain analyze update projects set misc = misc - 'foo'; > > Update on projects  (cost=0.00..4240.93 rows=10314 width=1149) > (actual time=346318.291..346318.295 rows=0 loops=1) >   ->  Seq Scan on projects  (cost=0.00..4240.93 rows=10314 > width=1149) (actual time=1.011..266.435 rows=10314 loops=1) > Planning time: 40.087 ms > Trigger trigger_populate_tsv_body_on_projects: time=341202.492 > calls=10314 > Execution time: 346320.260 ms > > Time: 345969.035 ms (05:45.969) > > > > On Wed, Jul 17, 2019 at 10:39 AM Adrian Klaver > > wrote: > > On 7/17/19 7:30 AM, Volkan Unsal wrote: > > I'm trying to remove a key from a jsonb column in a table > with 10K rows, > > and the performance is abysmal. When the key is missing, it > takes 5 > > minutes. When the key is present, it takes even longer. > > > > Test with non-existent key: > > > >  >> update projects set misc = misc - 'foo'; > > Time: 324711.960 ms (05:24.712) > > > > What can I do to improve this? > > Provide some useful information: > > 1) Postgres version > > 2) Table schema > > 3) Explain analyze of query > > > > -- > Adrian Klaver > adrian.klaver@aklaver.com > > > > -- > *Volkan Unsal* > /Product Engineer/ > volkanunsal.com > > > > -- > *Volkan Unsal* > /Product Engineer/ > volkanunsal.com -- Adrian Klaver adrian.klaver@aklaver.com