From issues-return-92439-archive-asf-public=cust-asf.ponee.io@ignite.apache.org Thu Feb 28 10:46:03 2019 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 51364180676 for ; Thu, 28 Feb 2019 11:46:03 +0100 (CET) Received: (qmail 8977 invoked by uid 500); 28 Feb 2019 10:46:02 -0000 Mailing-List: contact issues-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list issues@ignite.apache.org Received: (qmail 8822 invoked by uid 99); 28 Feb 2019 10:46:02 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Feb 2019 10:46:02 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id E53DE1816C1 for ; Thu, 28 Feb 2019 10:46:01 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -110.301 X-Spam-Level: X-Spam-Status: No, score=-110.301 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id xbTbFKJM4zlF for ; Thu, 28 Feb 2019 10:46:01 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id B722C5F560 for ; Thu, 28 Feb 2019 10:46:00 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 57C2AE2792 for ; Thu, 28 Feb 2019 10:46:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 19D0524578 for ; Thu, 28 Feb 2019 10:46:00 +0000 (UTC) Date: Thu, 28 Feb 2019 10:46:00 +0000 (UTC) From: "Roman Kondakov (JIRA)" To: issues@ignite.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (IGNITE-11448) SQL: Wrong results of select with aggregates in subquery MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 Roman Kondakov created IGNITE-11448: --------------------------------------- Summary: SQL: Wrong results of select with aggregates in subquery Key: IGNITE-11448 URL: https://issues.apache.org/jira/browse/IGNITE-11448 Project: Ignite Issue Type: Bug Components: sql Reporter: Roman Kondakov Attachments: Subquery reproducer Subqueries with aggregates may return wrong results due to incorrect splitting. Let's consider a table {{person}}: {noformat} SELECT id, firstName FROM person: [1, firstName1], [2, firstName2], [3, firstName3], [4, firstName4], [5, firstName5], [6, firstName6], [7, firstName7], [8, firstName8], [9, firstName9], [10, firstName10] {noformat} The result of query {{SELECT COUNT(\*) FROM person}} is {{10}}, which is correct. The result of query {{SELECT * FROM person WHERE id = 10}} is {{[10, firstName10]}}, which is also correct. But the result of the query {{SELECT * FROM person WHERE id = (SELECT COUNT(\*) FROM person)}} is {{[1, firstName1]}} which is completely wrong. The root cause of this behavior is the incorrect query splitting. The latest query is split into these parts: Map: {noformat} SELECT __Z0.ID __C0_0, __Z0.FIRSTNAME __C0_1 FROM PUBLIC.PERSON __Z0 WHERE __Z0.ID = (SELECT COUNT(*) FROM PUBLIC.PERSON __Z1) {noformat} Reduce: {noformat} SELECT __C0_0 ID, __C0_1 FIRSTNAME FROM PUBLIC.__T0 {noformat} As we can see, aggregate {{COUNT(\*)}} is calculated locally on each map node instead of calculating a single global aggregate and then using it in predicate. Reproducer is attached. -- This message was sent by Atlassian JIRA (v7.6.3#76005)