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 1pAYfd-0001hN-Ub for pgsql-performance@arkaria.postgresql.org; Wed, 28 Dec 2022 15:48:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pAYfc-0000tG-Gm for pgsql-performance@arkaria.postgresql.org; Wed, 28 Dec 2022 15:48:44 +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 1pAYfc-0000t7-3h for pgsql-performance@lists.postgresql.org; Wed, 28 Dec 2022 15:48:44 +0000 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pAYfY-0003wO-KB for pgsql-performance@lists.postgresql.org; Wed, 28 Dec 2022 15:48:42 +0000 Received: by mail-il1-x12f.google.com with SMTP id j28so8343905ila.9 for ; Wed, 28 Dec 2022 07:48:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=2on6iKZi82rQrkapoZciMws2rSQ8JtEW0kaZX8EqEpo=; b=8TjIW+p7WHX7Uv83ZnQWAzO3PJ1ywqfaThZXKdesVM06dPwWbkGzU4dP5rugvrbeYt i4DjJo2a6O7t8USfkbB5Eqzo89VZd8ZToiYeVHyz/ErSPORfzZYb+/i5WMsCDt67bTRw EJbSIdWVd6BCTw2OHecMM03PZCIPjQLoDbpgOuSgD3vmVp+r0BpvhN4ndK4jzSKndPPZ tTWHMMZZPWAbrHPtTKQ5MuTfn7vKzIR75g35zSPZADpwWOCq+hIqNvifDmrM//yqO6E9 C0KwNNzZXW0B/2aCGKi6Hvdcf+mZWlAKv/Ni8Gzoa8o6kCgnK4Lk8reP3Di2pfwp+93T xU4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2on6iKZi82rQrkapoZciMws2rSQ8JtEW0kaZX8EqEpo=; b=B3h2zzkaubZZf/qXAl/3dxiGol8UoocRS4ZhAHwkjgSZSXX6CLlmxfzhPkeBmbjDGP gAwyz6uLaX/tw6P06lx+5sOIHWOrZW8cN3aesGag9x97e+yTFtDpPI/w1slgSEeMsWYx HLOIyHB2VHsEezrgyHPcqIfde7KHG2noPe9X459iIaXO9xDDAHEfdHJY0NA9Rx+sZ0S1 9Db8GsxeQ4KTMS958kt9LNZtyL9XphJUOTbZ/FHp0KOeGUypAyfLuxY0E1FjVZ55g5Da l/KYuebkp33ZyjfHo0Zm8xrnWGdqqzQy0HQHtMNAvuIe320lPFJxBaz4XIdQ/1kp3Hwg CReg== X-Gm-Message-State: AFqh2kpUx77E69qQJlOKfW3pB5LKt8WLFcdwb69uWMk56dXE1Pq0Xwvs a/4VoTykOtmZQ8GSDwUdmj+GUw== X-Google-Smtp-Source: AMrXdXvBgGy+ATupL/NyWoaADDmz9V9inugCGLFtNrI2nEPbdjPjXYVAeUYjajt+iAy8X3gR6UE+lA== X-Received: by 2002:a92:d3c7:0:b0:30b:eca9:5601 with SMTP id c7-20020a92d3c7000000b0030beca95601mr12864826ilh.10.1672242519565; Wed, 28 Dec 2022 07:48:39 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id z9-20020a92cd09000000b00305e28bd099sm5022225iln.35.2022.12.28.07.48.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 07:48:39 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id DFC49800A27; Wed, 28 Dec 2022 09:48:37 -0600 (CST) Date: Wed, 28 Dec 2022 09:48:37 -0600 From: Justin Pryzby To: Gunther Schadow Cc: pgsql-performance@lists.postgresql.org Subject: Re: When you really want to force a certain join type? Message-ID: <20221228154837.GX1153@telsasoft.com> References: <70b2ee7b-8e8b-d884-8ca2-590a242308b8@gusw.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <70b2ee7b-8e8b-d884-8ca2-590a242308b8@gusw.net> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Dec 28, 2022 at 10:39:14AM -0500, Gunther Schadow wrote: > I have a complex query which essentially runs a finite state automaton > through a with recursive union, adding the next state based on the > previous.  This is run at 100,000 or a million start states at the same > time, picking a new record (token), matching it to the FSA (a three-way > join: > There are 100s of thousands of states. This join has a HUGE fan out if it is > I doubt that I can find any trick to give to the planner better data which > it can then use to figure out that the merge join is a bad proposition. > Note, for my immediate relief I have forced it by simply set > enable_mergejoin=off. This works fine, except, it converts both into a > nested loop, but the upper merge join was not a problem, and sometimes (most > often) nested loop is a bad choice for bulk data. It's only for this > recursive query it sometimes makes sense. Maybe the new parameter in v15 would help. https://www.postgresql.org/docs/15/runtime-config-query.html#GUC-RECURSIVE-WORKTABLE-FACTOR recursive_worktable_factor (floating point) Sets the planner's estimate of the average size of the working table of a recursive query, as a multiple of the estimated size of the initial non-recursive term of the query. This helps the planner choose the most appropriate method for joining the working table to the query's other tables. The default value is 10.0. A smaller value such as 1.0 can be helpful when the recursion has low “fan-out” from one step to the next, as for example in shortest-path queries. Graph analytics queries may benefit from larger-than-default values. -- Justin