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 1pmAO5-0005gO-Er for pgsql-sql@arkaria.postgresql.org; Tue, 11 Apr 2023 09:34:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pmAO4-0004BS-BV for pgsql-sql@arkaria.postgresql.org; Tue, 11 Apr 2023 09:34:04 +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 1pmAO4-0004BH-14 for pgsql-sql@lists.postgresql.org; Tue, 11 Apr 2023 09:34:04 +0000 Received: from mail-yb1-xb29.google.com ([2607:f8b0:4864:20::b29]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pmANv-0001oX-LI for pgsql-sql@lists.postgresql.org; Tue, 11 Apr 2023 09:34:02 +0000 Received: by mail-yb1-xb29.google.com with SMTP id bv15so5582667ybb.1 for ; Tue, 11 Apr 2023 02:33:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1681205634; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=/eQ/9dfQUx/DAjfYXu2sZ6Ywg8a0kUt6wCmnL5AdaaY=; b=QO4NqiCR3w7hetUPak2HSbjB/W5Cv602Jrp/VSa6x34MZoxiducAPVmOrYjl+rp0PZ 6dnY4mm6BULu/N0auNro747FqP2t+Whp5fhXjCJ93Yr6aB3kxGBgC74dayP8sLGReXBx CQU3y2Q20GlGuWrqTCGf4tImE7nZ9wOZ775z0nWe5623yA0dYXQduI2BCwTR2SGLF47g YDvmEUnmmcUkakaunItoWQ2IAJwBhEDtR/K84J/FMyVlJbphCOBSKp2kQlkawOhN7yv2 nDxZaINCoZGQCDmDqYB9aoiJpMcfhOdJxWfuz47Bny5GKvGb2xuLx8Y6oaXPbTgdFKGh 9doA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681205634; h=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=/eQ/9dfQUx/DAjfYXu2sZ6Ywg8a0kUt6wCmnL5AdaaY=; b=tSB7Wlo+dqi0wlPVGH0dUjid2JbfEt8iztQKvQwAteepUIng/2zdoC1dp9jgwlYG8g /SY6FpKu8Z/hXO5QEtFXliaLKqyz6u39BqURdgeQCRb1xZg1GFVd+czle22fCbsDW1wK kt5GDb7ht2jsBcdHROXzpqAaVVuqj0RJaD93oPJbViooGDszINLaDzu6V5zLghKLGYlb LCna3XD13L740pcCXYjMYIOX/j5WVfZjhhifRu9wk9mvNjiR4i+iY8Mpg8zMucye+jfz ZQts+kbSJEXmXzX5mPaxlqCsf/K+CvaaWjJMEuF+cQuITKPTLSuWliETMBqa089BtQoC Wwfg== X-Gm-Message-State: AAQBX9ecM6YgxZImqto4gFnrhhp3HA9vYnzLo3C6LR3dV0ccqRJ+KNgV NhDrWAqX9dal/54jn9jSIRZoNuQ6OOUfHh+Qx4g= X-Google-Smtp-Source: AKy350bp0LRfrl0eQCyq5E0L7RcEfBPJO6PTeYHGl0D5AEgl9WtXTrtwqstZ6q7GALAteAYfjI4qY+0KAom5x1+N0fE= X-Received: by 2002:a25:6fd4:0:b0:b8e:cb88:1b8a with SMTP id k203-20020a256fd4000000b00b8ecb881b8amr6854168ybc.8.1681205634597; Tue, 11 Apr 2023 02:33:54 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: David Rowley Date: Tue, 11 Apr 2023 21:33:42 +1200 Message-ID: Subject: Re: Looking for an efficient way to replace efficient NOT IN when landling very large data To: Shaozhong SHI Cc: pgsql-sql Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 11 Apr 2023 at 21:28, Shaozhong SHI wrote: > > Select a.id, a.name, b.id, b.name from a_large_table a, definitive b where (a.id, b.name) not in > (select b.id, b.name from definitive b) > > is very slow. > > Is there a faster way to do so? It depends on what your exact requirements are for the NULL handling that NOT IN provides. Do you need the query to return 0 rows if b.id and b.name are null? This question is moot if none of the columns or either table allow NULLs. If you don't require that, then you'll give the planner more flexibility to choose a more efficient plan if you use NOT EXISTS instead. David