Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 20315 invoked from network); 27 Oct 2009 14:12:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Oct 2009 14:12:23 -0000 Received: (qmail 84146 invoked by uid 500); 27 Oct 2009 14:12:23 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 84114 invoked by uid 500); 27 Oct 2009 14:12:23 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 84106 invoked by uid 99); 27 Oct 2009 14:12:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Oct 2009 14:12:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Oct 2009 14:12:20 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 5F507234C045 for ; Tue, 27 Oct 2009 07:11:59 -0700 (PDT) Message-ID: <1518786184.1256652719383.JavaMail.jira@brutus> Date: Tue, 27 Oct 2009 14:11:59 +0000 (UTC) From: "Bryan Pendleton (JIRA)" To: derby-dev@db.apache.org Subject: [jira] Commented: (DERBY-4421) Allow Visitors to process the nodes bottom-up In-Reply-To: <799935563.1256296799485.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/DERBY-4421?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12770515#action_12770515 ] Bryan Pendleton commented on DERBY-4421: ---------------------------------------- Thanks Knut for taking the time to work through the details. I think this is a good change and I'm excited about the improved optimization behaviors! > Allow Visitors to process the nodes bottom-up > --------------------------------------------- > > Key: DERBY-4421 > URL: https://issues.apache.org/jira/browse/DERBY-4421 > Project: Derby > Issue Type: Improvement > Components: SQL > Affects Versions: 10.6.0.0 > Reporter: Knut Anders Hatlen > Assignee: Knut Anders Hatlen > Priority: Minor > Attachments: d4421-1a.diff, d4421-1a.stat > > > Currently, QueryTreeNode.accept() walks the tree top-down, always calling > visit() on the parent before it calls visit() on the children. Although this > is fine in most cases, there are use cases where visiting the nodes > bottom-up would be better. One example is mentioned in DERBY-4416. The > visitor posted there looks for binary comparison operators and checks > whether both operands are constants. If they are, the operator is replaced > with a boolean constant. > Take this expression as an example: (1<2)=(2>1) > The query tree looks like this: > = > / \ > / \ > < > > / \ / \ > / \ / \ > 1 2 2 1 > If we walk the tree top-down with the said visitor, the = node doesn't have > constant operands when it's visited. The < and > operators do have constant > operands, and they're both replaced with constant TRUE. This means the > expression (1<2)=(2>1) is rewritten to TRUE=TRUE, and that's how far the > transformation goes. > If the tree had been processed bottom-up, we would start with the < and > > operators, and again replace them with TRUE. The query tree would therefore > have been transformed to this intermediate form when the = operator was > visited: > = > / \ > / \ > TRUE TRUE > This is the same as the end result when visiting top-down, but now the = > operator hasn't been visited yet. Since both the operands of the = operator > are constants, the visitor will perform yet another transformation so the > tree is simplified further and ends up as: > TRUE -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.