Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YxBrI-0005x5-Gl for pgsql-hackers@arkaria.postgresql.org; Tue, 26 May 2015 10:13:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YxBrI-00078d-14 for pgsql-hackers@arkaria.postgresql.org; Tue, 26 May 2015 10:13:16 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YxBrG-00078X-OG for pgsql-hackers@postgresql.org; Tue, 26 May 2015 10:13:14 +0000 Received: from mail-wi0-f175.google.com ([209.85.212.175]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1YxBrD-0003kg-7y for pgsql-hackers@postgresql.org; Tue, 26 May 2015 10:13:13 +0000 Received: by wicmx19 with SMTP id mx19so71510366wic.0 for ; Tue, 26 May 2015 03:13:09 -0700 (PDT) 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:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=xXqsMDwyqk1UScwmeEVYP8Xu8hSodFbeq44cexkiizM=; b=OpfDNKLE73pj9MFbEWBOZ0AHHW+jK44+bfrhfycFwqfqdBAs5lNY5+DAICrxnG3k35 ZWUAZ5XZSYK071iT4ZOi2y5UWhzb7AYYOdDaZ5ue4eIlloFKZ9OtNsb/uOQ8XWKC+/5N 21E0OapUtajFKbazPs0zXddzpkzfHGIjR3krZDA1msBxcWWJx3K2K5i2W7MrqG813dvn +5XkbC87uThUwZaIX5aLogBywQ1gUf07s/sJ741/Y0UV4L6jVnfqxLGhxRinE83yfUtN JwPV2FehOv/syDgbajW8nMHCp4Dw89wQKLsyH9UMWkDkcCHqiA+HMc35T5Wv9sIezJZr gXlA== X-Gm-Message-State: ALoCoQkGp0hLFu+CmTS5UDFVkmPLrCgfa1eOjM2BVXnvQ86pqtTp8s7pL7Kbu7CPGEZVw8hyfThC X-Received: by 10.180.95.67 with SMTP id di3mr29298810wib.78.1432635189057; Tue, 26 May 2015 03:13:09 -0700 (PDT) Received: from [10.1.0.101] (190.84.broadband17.iol.cz. [109.80.84.190]) by mx.google.com with ESMTPSA id js3sm20990885wjc.5.2015.05.26.03.13.07 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 May 2015 03:13:08 -0700 (PDT) Message-ID: <55644732.8050506@2ndquadrant.com> Date: Tue, 26 May 2015 12:13:06 +0200 From: Petr Jelinek User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: CK Tan , Colin 't Hart CC: PostgreSQL mailing lists , Amit Langote Subject: Re: Order of columns in query is important?! References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.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 On 26/05/15 11:59, CK Tan wrote: > It has to do with the implementation of slot_getattr, which tries to do > the deform on-demand lazily. > > if you do select a,b,c, the execution would do slot_getattr(1) and > deform a, and then slot_getattr(2) which reparse the tuple to deform b, > and finally slot_getattr(3), which parse the tuple yet again to deform c. > > Where as if you do select c, b, a, it would do slot_getattr(3) to deform > c, and in the process deform a and b in one pass. Subsequent calls to > slot_getattr 1 and 2 would find the attribute ready and available, and > return it (without parsing the tuple again). > If this was the case, changing column order would lead to performance increase, not decrease as reported. My guess would be same as Amits, it's most likely the additional projection step. -- Petr Jelinek http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, 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