Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YQm7X-0000mb-JH for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Feb 2015 00:16:03 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YQm7W-0005sh-M8 for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Feb 2015 00:16:02 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YQm7V-0005sK-Ba for pgsql-hackers@postgresql.org; Thu, 26 Feb 2015 00:16:01 +0000 Received: from mail-wi0-f171.google.com ([209.85.212.171]) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YQm7N-0004S1-My for pgsql-hackers@postgresql.org; Thu, 26 Feb 2015 00:15:59 +0000 Received: by mail-wi0-f171.google.com with SMTP id ex7so16727287wid.4 for ; Wed, 25 Feb 2015 16:15:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:organization:user-agent :mime-version:to:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=ixRsP/6v/ItSbW1FazIIrd0Msf/xxHEh3BWRI0IDMwA=; b=iUMWVbsj2Q67NaNosmNzMltqWPjO1rEfdag1L46qTWQ83LVxikug2TyMAP2VVUSHnN eiV9EIF3Lb6XhNgtwczGSK+m1muODPK+bjGfWmehGtlYm1HCHbqxi7SjH8hSHdwp8Pj7 u1Kkwj8Ct19IrXz3pbEUNTJ7obpf+s9dXLitmrxFdk+R36E8aZc/eWcNHko3/mki+N5D wvbPuUxiolyggdlY/+bzSvikhSIM1MVH1xiWIBEW7FfcHjSd6c1r57zGwnOPuOf16K1C hj29SoNA80D+Z7dOsZga5FimtagoeMXX3tQdJE6vZedPF8ktrIopXzBvkRqoTehjfubm Ce7g== X-Gm-Message-State: ALoCoQlN94ls3I7H+UU9oiHH+3Ds+ajx6PvvjXpW2TouMhXEZODmURMTsFWBcSdukv9YaaYYCeO1Wx8xB3aszDbLs5u8Ul5DFcKYYQSNDUHPVljVS1hk1z3QEFtFrOwbq2nyZmRf16VxXa7xspthpKcKSSsc9Tk3MMhHFh09N+IAN5sdwm2goREUWykHE+x4TLxYtjvZyN9z X-Received: by 10.194.75.168 with SMTP id d8mr2959258wjw.87.1424909751590; Wed, 25 Feb 2015 16:15:51 -0800 (PST) Received: from [192.168.1.163] (ip-78-45-139-138.net.upcbroadband.cz. [78.45.139.138]) by mx.google.com with ESMTPSA id dt7sm27322778wib.19.2015.02.25.16.15.50 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Feb 2015 16:15:50 -0800 (PST) Message-ID: <54EE659F.8050004@2ndquadrant.com> Date: Thu, 26 Feb 2015 01:15:27 +0100 From: Tomas Vondra Organization: 2ndQuadrant User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: David Rowley , PostgreSQL-development Subject: Re: Performance improvement for joins where outer side is unique References: In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Hi, I tried to do an initdb with the patch applied, and seems there's a bug somewhere in analyzejoins.c: tomas@rimmer ~ $ pg_ctl -D tmp/pg-unidata init The files belonging to this database system will be owned by user "tomas". This user must also own the server process. The database cluster will be initialized with locale "en_US". The default database encoding has accordingly been set to "LATIN1". The default text search configuration will be set to "english". Data page checksums are disabled. creating directory tmp/pg-unidata ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting dynamic shared memory implementation ... sysv creating configuration files ... ok creating template1 database in tmp/pg-unidata/base/1 ... ok initializing pg_authid ... ok initializing dependencies ... ok creating system views ... ok loading system objects' descriptions ... TRAP: FailedAssertion("!(index_vars != ((List *) ((void *)0)))", File: "analyzejoins.c", Line: 414) sh: line 1: 339 Aborted "/home/tomas/pg-unijoins/bin/postgres" --single -F -O -c search_path=pg_catalog -c exit_on_error=true template1 > /dev/null child process exited with exit code 134 initdb: removing data directory "tmp/pg-unidata" pg_ctl: database system initialization failed The problem seems to be the last command in setup_description() at src/bin/initdb/initdb.c:1843, i.e. this query: WITH funcdescs AS ( SELECT p.oid as p_oid, oprname, coalesce(obj_description(o.oid, 'pg_operator'),'') as opdesc FROM pg_proc p JOIN pg_operator o ON oprcode = p.oid ) INSERT INTO pg_description SELECT p_oid, 'pg_proc'::regclass, 0, 'implementation of ' || oprname || ' operator' FROM funcdescs WHERE opdesc NOT LIKE 'deprecated%' AND NOT EXISTS (SELECT 1 FROM pg_description WHERE objoid = p_oid AND classoid = 'pg_proc'::regclass) And particularly the join in the CTE, i.e. this fails SELECT * FROM pg_proc p JOIN pg_operator o ON oprcode = p.oid I'm not quite sure why, but eclassjoin_is_unique_join() never actually jumps into this part (line ~400): if (relvar != NULL && candidaterelvar != NULL) { ... index_vars = lappend(index_vars, candidaterelvar); ... } so the index_vars is NIL. Not sure why, but I'm sure you'll spot the issue right away. BTW, I find this coding (first cast, then check) rather strange: Var *var = (Var *) ecm->em_expr; if (!IsA(var, Var)) continue; /* Ignore Consts */ It's probably harmless, but I find it confusing and I can't remember seeing it elsewhere in the code (for example clausesel.c and such) use this style: ... clause is (Node*) ... if (IsA(clause, Var)) { Var *var = (Var*)clause; ... } or Var * var = NULL; if (! IsA(clause, Var)) // error / continue var = (Var*)clause; -- Tomas Vondra http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers