Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m1fpE-0002rZ-39 for pgsql-performance@arkaria.postgresql.org; Fri, 09 Jul 2021 02:01:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m1fpC-0000m0-GV for pgsql-performance@arkaria.postgresql.org; Fri, 09 Jul 2021 02:01:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m1fpC-0000lH-6Y for pgsql-performance@lists.postgresql.org; Fri, 09 Jul 2021 02:01:06 +0000 Received: from mail-qk1-x72c.google.com ([2607:f8b0:4864:20::72c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m1fp5-0003mI-QB for pgsql-performance@lists.postgresql.org; Fri, 09 Jul 2021 02:01:05 +0000 Received: by mail-qk1-x72c.google.com with SMTP id a6so7828689qka.4 for ; Thu, 08 Jul 2021 19:00:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=jelCmwCCVphflklf/kIed9RuxJTc2KvqsiOGsm51JN4=; b=TX9OPa6fTTCT3RVMkPz2B4kch7bBTHbmcsJsYOlzsdBI3pvkkezZigs5EveyhLBaee /7JU47yM1IYoBOa/LxIU434WSNHLLLSG52yApcQ/a3UQC786OvSc2IS5H7F+Shs4zRqn /3S7r4XlEma9BV+rA77oF8e890v+/pnR/BLwezo8NWAiKmihZgh/g4uMFenTqz1SNvSu Vgm5vlZdz9Y25ip+YoZZFgO+J+Ag0R6whyP30T5akZzDooBoGBPyXN0srkFbAX/k39n3 1YBp01OIV8JQjp8jfYkzAZKXUEHFNxutby0ZeBkIiNXq31H+jiE7wyLyzSU2AoeA0Sd1 WvNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=jelCmwCCVphflklf/kIed9RuxJTc2KvqsiOGsm51JN4=; b=YJf+zsmsLPguOXAx0RWvbOjGFgtrmVsftJb9PJCC7p7ihjHfRWpppknx67K61Zb6WG BDG57rzvRftwIjrUY66IKsEs/DZzOB5W9KcdSLWpUXiPDMXQjT5nXqHsMwTl/HOqIy0T VJal+9lJ4V/env/VLPDVCf2Ld1kX98YUcHnJKPYPsY6/TsBM5Di7zb2jtLoilg9f126/ i4eRIraaGVftK3diRjrDok9RA7yA2EK6JigUEIbROt3crJYrXHmrT+aLP9y4MO6zJGqX P77za7/zdT5Ft/mXINwA2E7ZC8ibNsKeaUjdBoxuLFCc+VUkiQ85ggQ+Q4o3sKaIQuO0 5Ytg== X-Gm-Message-State: AOAM530RjmLlddSuUn+73ccrXOA5c3BJxkpU2KqoXHMZNY9WJRJvTOZV ++rDluadcfASzJgyeSDuZuE= X-Google-Smtp-Source: ABdhPJw/JLBOmc4v3XGK0Kl4ZTwyVmRLwTqFp5AzTwlkv8Usn7+QGaL0+dKI2b3F6/OYI+6XpX47xw== X-Received: by 2002:ae9:c116:: with SMTP id z22mr32071163qki.111.1625796058202; Thu, 08 Jul 2021 19:00:58 -0700 (PDT) Received: from smtpclient.apple (190-21-43-31.baf.movistar.cl. [190.21.43.31]) by smtp.gmail.com with ESMTPSA id d24sm1829150qkk.61.2021.07.08.19.00.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Jul 2021 19:00:57 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.100.0.2.22\)) Subject: Re: Strange execution plan From: Manuel Weitzman In-Reply-To: <9F9D5E5E-6C58-4815-A20A-84216B788AD1@gmail.com> Date: Thu, 8 Jul 2021 22:00:54 -0400 Cc: Pgsql Performance Content-Transfer-Encoding: 7bit Message-Id: References: <17a8539f896.10fc10eb5173534.6306217358025168810@car-expresso.com> <9F9D5E5E-6C58-4815-A20A-84216B788AD1@gmail.com> To: Joel Frid X-Mailer: Apple Mail (2.3654.100.0.2.22) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 08-07-2021, at 17:13, Manuel Weitzman wrote: > > Option A: Use a common table expression to "force" the usage of > test_json_data_idx > > WITH json_matching_rows AS ( > SELECT t.* > FROM test ti > WHERE t.json_data @> '{"book":{"title":"In Search of Lost Time"}}' > ) > SELECT t.* > FROM json_matching_rows t > WHERE t."existe" IS true > ORDER BY t."id" DESC > LIMIT 100 OFFSET 0; > The first query line should be WITH MATERIALIZED json_matching_rows AS ( I had forgotten that Postgres 12 removed the optimization barrier on common table expressions. To introduce it again the MATERIALIZED clause is needed. Apparently I need to work on reviewing my emails properly before sending them. Best regards, Manuel Weitzman