From issues-return-3517-archive-asf-public=cust-asf.ponee.io@phoenix.apache.org Sat Dec 22 04:11:37 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 70DBA180627 for ; Sat, 22 Dec 2018 04:11:37 +0100 (CET) Received: (qmail 68990 invoked by uid 500); 22 Dec 2018 03:11:36 -0000 Mailing-List: contact issues-help@phoenix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.apache.org Delivered-To: mailing list issues@phoenix.apache.org Received: (qmail 68981 invoked by uid 99); 22 Dec 2018 03:11:36 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Dec 2018 03:11:36 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 40348E0ABE; Sat, 22 Dec 2018 03:11:36 +0000 (UTC) From: comnetwork To: issues@phoenix.apache.org Reply-To: issues@phoenix.apache.org References: In-Reply-To: Subject: [GitHub] phoenix pull request #417: PHOENIX-4820 Content-Type: text/plain Message-Id: <20181222031136.40348E0ABE@git1-us-west.apache.org> Date: Sat, 22 Dec 2018 03:11:36 +0000 (UTC) Github user comnetwork commented on a diff in the pull request: https://github.com/apache/phoenix/pull/417#discussion_r243724103 --- Diff: phoenix-core/src/main/java/org/apache/phoenix/compile/OrderByCompiler.java --- @@ -88,7 +88,8 @@ public static OrderBy compile(StatementContext context, Integer offset, RowProjector rowProjector, TupleProjector tupleProjector, - boolean isInRowKeyOrder) throws SQLException { + boolean isInRowKeyOrder, + Expression whereExpression) throws SQLException { --- End diff -- We need the whereExpression because in OrderPreservingTracker.IsConstantVisitor, we need whereExpression to help us to check the columnExpression is constant or not. Just take the same sql as example: select a.ak3 from (select rand() ak1,length(pk2) ak2,length(pk3) ak3,length(v1) av1,length(v2) av2 from test order by pk2,pk3 limit 10) a where a.ak1 = 0.0 and a.av2 = length(substr('abc',1,1)) group by a.ak3,CASE WHEN coalesce(a.ak1,1) > coalesce(a.av2,2) THEN coalesce(a.ak1,1) ELSE coalesce(a.av2,2) END,a.av1 order by a.ak3,a.av1 We need to check if "CASE WHEN coalesce(a.ak1,1) > coalesce(a.av2,2) THEN coalesce(a.ak1,1) ELSE coalesce(a.av2,2) END,a.av1" is constant in OrderPreservingTracker.hasEqualityConstraints method, so we move forward to check if the a.ak1 and a.av2 are constant in OrderPreservingTracker.IsConstantVisitor, and we must visit the where clause "where a.ak1 = 0.0 and a.av2 = length(substr('abc',1,1))" to check the a.ak1 and a.av2. BTW. There is no whereExpression in current code of OrderByCompiler because for PHOENIX-3451 which was completed by James and me before, RowKeyColumnExpression is only supported to check in OrderPreservingTracker.hasEqualityConstraints, and two FIXME tags were left in this method at at time: private boolean hasEqualityConstraints(int startPos, int endPos) { ScanRanges ranges = context.getScanRanges(); // If a GROUP BY is being done, then the rows are ordered according to the GROUP BY key, // not by the original row key order of the table (see PHOENIX-3451). // We check each GROUP BY expression to see if it only references columns that are // matched by equality constraints, in which case the expression itself would be constant. // FIXME: this only recognizes row key columns that are held constant, not all columns. // FIXME: we should optimize out any GROUP BY or ORDER BY expression which is deemed to // be held constant based on the WHERE clause. if (!groupBy.isEmpty()) { In this patch, I added whereExpression to try to fix this problem to support non-pk columns also. ---