Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rhiZQ-00D0qn-4y for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Mar 2024 04:07:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rhiZO-005Bhh-7D for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Mar 2024 04:07:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rhiZN-005BhU-U4 for pgsql-hackers@lists.postgresql.org; Wed, 06 Mar 2024 04:07:54 +0000 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rhiZK-0034gr-Gw for pgsql-hackers@postgresql.org; Wed, 06 Mar 2024 04:07:52 +0000 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-5d8b70b39efso5815096a12.0 for ; Tue, 05 Mar 2024 20:07:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709698070; x=1710302870; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=lbWQwvnInGrgLRl0JrrLSXM/iEdiBDIuEqRNlQTZolY=; b=kqg+IewgR6DWJlvi78scVyeGxoR5dlPV0wVMkM4fKV1qUqlbOMgUDdA7tyCVZ9x8Oq 566xCLIz4zkDq16e04wqX2/fJbjV/WH4gGUJObyqjlbPt+tCvpbKq0xvu0EcgOsfD2U/ yckD0ClRqRjJb3fNTlQlDF8/JqtmT1W9zbYNVrT8nXI+aj0WeBEcf4fBQQtHv0Yty1wV SQsYXGfMQW1qM3K9GSQDO/ZkeU7PfvpFXTAYsiaIW4YfubJEtJlz9mm7/l4gT7NgBLoq 2in/g73hfmV8+4IDyHK0p3p7Z/ZLjDXpY/k9xrWW2zGllVpuSm2KzFHF0e3IQ/20Uqdq vVsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709698070; x=1710302870; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lbWQwvnInGrgLRl0JrrLSXM/iEdiBDIuEqRNlQTZolY=; b=c1Qw4n8UGM1foDj6yLUor1l63OtrK7bp4VOWOE6Lg0FA0QyvnjVX/Vqrq4dJ/zBSEB SagSwxt+ck1HcSV6HkCgNII7FC++bGf0AwY72uqp4BCt6XW3xFsc73pNN+WxpwRX/wO4 mbFtXTOM+6cqUrnWcaEMRuJ1GAqAvX2hesyvv4/ShlXp964+fbXZpv0UudI+oZGxBHAg Z5WWaTsLlWCoRiJoDe3s0QkBFEuJkAD+eGBRxIBNACriqZNCXaHA1GguhRcSdXfmojVy bsJmgqZ1SBS9zrpQyJHhqIZv+O+qYJWTJrIxnKMHvSYDyfsYz3q3jpv6ups0T75XrUt5 rrSw== X-Forwarded-Encrypted: i=1; AJvYcCXiYsj8K5mX0GCIDbxaRYCEhM0XKfnwRX+GRzRwwU+11K0lvImftfczXaw6W1/Lezoxgq8UDW5fF6A3ghpoNE6G+bAD54eiJyCUy7hZ X-Gm-Message-State: AOJu0YwZdorIE+pS0aDf3JwMPgIyvfdDaKUKjDOmrii2iLDKbEO85ZEq cxkA11GdwveWk+Y7aTxHj4dpjxgkap0kCCEdNwzOLLF8Cgt3ex8WKk0fSE1qMJoZCmV8QLa3I6w qaO06K0OW7OuD4+alYeSe9e/9UYE= X-Google-Smtp-Source: AGHT+IHBPv00eVupec6dFlOXd+jrU2UALlSrUJVpwr8B20cZYXdCZI8e3HDvwXCEIL7NhVN0CdFwmUJJenhhK+XT9sI= X-Received: by 2002:a05:6a20:1e5e:b0:1a1:4ca8:da1e with SMTP id cy30-20020a056a201e5e00b001a14ca8da1emr2770091pzb.52.1709698070036; Tue, 05 Mar 2024 20:07:50 -0800 (PST) MIME-Version: 1.0 References: <1cee81f3-312f-30e3-0282-c4df7ee72f93@xs4all.nl> <202403041503.5momp6knupgo@alvherre.pgsql> <1e0e5800-965e-42ed-8caa-362294604243@enterprisedb.com> In-Reply-To: <1e0e5800-965e-42ed-8caa-362294604243@enterprisedb.com> From: Amit Langote Date: Wed, 6 Mar 2024 13:07:33 +0900 Message-ID: Subject: Re: remaining sql/json patches To: Tomas Vondra Cc: Alvaro Herrera , Erik Rijkers , jian he , Andres Freund , Andrew Dunstan , PostgreSQL-development Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Tomas, On Wed, Mar 6, 2024 at 6:30=E2=80=AFAM Tomas Vondra wrote: > > Hi, > > I know very little about sql/json and all the json internals, but I > decided to do some black box testing. I built a large JSONB table > (single column, ~7GB of data after loading). And then I did a query > transforming the data into tabular form using JSON_TABLE. > > The JSON_TABLE query looks like this: > > SELECT jt.* FROM > title_jsonb t, > json_table(t.info, '$' > COLUMNS ( > "id" text path '$."id"', > "type" text path '$."type"', > "title" text path '$."title"', > "original_title" text path '$."original_title"', > "is_adult" text path '$."is_adult"', > "start_year" text path '$."start_year"', > "end_year" text path '$."end_year"', > "minutes" text path '$."minutes"', > "genres" text path '$."genres"', > "aliases" text path '$."aliases"', > "directors" text path '$."directors"', > "writers" text path '$."writers"', > "ratings" text path '$."ratings"', > NESTED PATH '$."aliases"[*]' > COLUMNS ( > "alias_title" text path '$."title"', > "alias_region" text path '$."region"' > ), > NESTED PATH '$."directors"[*]' > COLUMNS ( > "director_name" text path '$."name"', > "director_birth_year" text path '$."birth_year"', > "director_death_year" text path '$."death_year"' > ), > NESTED PATH '$."writers"[*]' > COLUMNS ( > "writer_name" text path '$."name"', > "writer_birth_year" text path '$."birth_year"', > "writer_death_year" text path '$."death_year"' > ), > NESTED PATH '$."ratings"[*]' > COLUMNS ( > "rating_average" text path '$."average"', > "rating_votes" text path '$."votes"' > ) > ) > ) as jt; > > again, not particularly complex. But if I run this, it consumes multiple > gigabytes of memory, before it gets killed by OOM killer. This happens > even when ran using > > COPY (...) TO '/dev/null' > > so there's nothing sent to the client. I did catch memory context info, > where it looks like this (complete stats attached): > > ------ > TopMemoryContext: 97696 total in 5 blocks; 13056 free (11 chunks); > 84640 used > ... > TopPortalContext: 8192 total in 1 blocks; 7680 free (0 chunks); ... > PortalContext: 1024 total in 1 blocks; 560 free (0 chunks); ... > ExecutorState: 2541764672 total in 314 blocks; 6528176 free > (1208 chunks); 2535236496 used > printtup: 8192 total in 1 blocks; 7952 free (0 chunks); ... > ... > ... > Grand total: 2544132336 bytes in 528 blocks; 7484504 free > (1340 chunks); 2536647832 used > ------ > > I'd say 2.5GB in ExecutorState seems a bit excessive ... Seems there's > some memory management issue? My guess is we're not releasing memory > allocated while parsing the JSON or building JSON output. > > I'm not attaching the data, but I can provide that if needed - it's > about 600MB compressed. The structure is not particularly complex, it's > movie info from [1] combined into a JSON document (one per movie). Thanks for the report. Yeah, I'd like to see the data to try to drill down into what's piling up in ExecutorState. I want to be sure of if the 1st, query functions patch, is not implicated in this, because I'd like to get that one out of the way sooner than later. --=20 Thanks, Amit Langote