Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 23922200D0E for ; Mon, 11 Sep 2017 17:57:09 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 224321609C4; Mon, 11 Sep 2017 15:57:09 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 4933D1609C3 for ; Mon, 11 Sep 2017 17:57:08 +0200 (CEST) Received: (qmail 87584 invoked by uid 500); 11 Sep 2017 15:57:07 -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 87575 invoked by uid 99); 11 Sep 2017 15:57:06 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Sep 2017 15:57:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 799F9DACF8 for ; Mon, 11 Sep 2017 15:57:06 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -100.002 X-Spam-Level: X-Spam-Status: No, score=-100.002 tagged_above=-999 required=6.31 tests=[RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id wWtbn0V3LT1j for ; Mon, 11 Sep 2017 15:57:05 +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 375515FD42 for ; Mon, 11 Sep 2017 15:57:05 +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 CAD8CE06BF for ; Mon, 11 Sep 2017 15:57:03 +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 D31F724147 for ; Mon, 11 Sep 2017 15:57:01 +0000 (UTC) Date: Mon, 11 Sep 2017 15:57:01 +0000 (UTC) From: "Vladimir Ozerov (JIRA)" To: issues@ignite.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (IGNITE-6343) Index is not used properly if changing sort order. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Mon, 11 Sep 2017 15:57:09 -0000 [ https://issues.apache.org/jira/browse/IGNITE-6343?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Vladimir Ozerov updated IGNITE-6343: ------------------------------------ Fix Version/s: (was: 2.3) > Index is not used properly if changing sort order. > -------------------------------------------------- > > Key: IGNITE-6343 > URL: https://issues.apache.org/jira/browse/IGNITE-6343 > Project: Ignite > Issue Type: Improvement > Affects Versions: 2.0 > Reporter: Alexei Scherbakov > Labels: sql > > Unit test reproducer: > {noformat} > /* > * Licensed to the Apache Software Foundation (ASF) under one or more > * contributor license agreements. See the NOTICE file distributed with > * this work for additional information regarding copyright ownership. > * The ASF licenses this file to You under the Apache License, Version 2.0 > * (the "License"); you may not use this file except in compliance with > * the License. You may obtain a copy of the License at > * > * http://www.apache.org/licenses/LICENSE-2.0 > * > * Unless required by applicable law or agreed to in writing, software > * distributed under the License is distributed on an "AS IS" BASIS, > * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > * See the License for the specific language governing permissions and > * limitations under the License. > */ > package org.apache.ignite.internal.processors.cache; > import java.util.Calendar; > import java.util.Collections; > import java.util.Date; > import java.util.LinkedHashMap; > import java.util.List; > import org.apache.ignite.IgniteCache; > import org.apache.ignite.cache.CacheMode; > import org.apache.ignite.cache.QueryEntity; > import org.apache.ignite.cache.QueryIndex; > import org.apache.ignite.cache.QueryIndexType; > import org.apache.ignite.cache.query.SqlFieldsQuery; > import org.apache.ignite.configuration.CacheConfiguration; > import org.apache.ignite.configuration.IgniteConfiguration; > import org.apache.ignite.configuration.MemoryConfiguration; > import org.apache.ignite.configuration.MemoryPolicyConfiguration; > import org.apache.ignite.internal.util.typedef.internal.U; > import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; > import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; > import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; > import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; > import static org.apache.ignite.cache.CacheMode.PARTITIONED; > import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; > import static java.util.Calendar.*; > /** > * Tests for cache query results serialization. > */ > public class GridCacheQueryIndexUsageSelfTest extends GridCommonAbstractTest { > /** */ > private static final int GRID_CNT = 1; > /** */ > private static final String CACHE_NAME = "A"; > /** */ > private static final CacheMode CACHE_MODE = PARTITIONED; > /** */ > private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); > /** {@inheritDoc} */ > @Override protected void beforeTest() throws Exception { > startGridsMultiThreaded(GRID_CNT); > } > /** {@inheritDoc} */ > @Override protected void afterTest() throws Exception { > stopAllGrids(); > } > /** {@inheritDoc} */ > @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { > IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); > MemoryPolicyConfiguration mpcfg = new MemoryPolicyConfiguration(); > //mpcfg.setMaxSize(2 * 1024 * 1024 * 1024L); > mpcfg.setName("def"); > MemoryConfiguration mcfg = new MemoryConfiguration(); > mcfg.setDefaultMemoryPolicyName("def"); > mcfg.setMemoryPolicies(mpcfg); > cfg.setMemoryConfiguration(mcfg); > TcpDiscoverySpi disco = new TcpDiscoverySpi(); > disco.setIpFinder(ipFinder); > cfg.setDiscoverySpi(disco); > CacheConfiguration cacheCfg = defaultCacheConfiguration(); > cacheCfg.setName(CACHE_NAME); > cacheCfg.setCacheMode(CACHE_MODE); > cacheCfg.setWriteSynchronizationMode(FULL_SYNC); > QueryEntity qe = new QueryEntity(); > qe.setKeyType(Long.class.getName()); > qe.setValueType(IndexedValue.class.getName()); > LinkedHashMap fields = U.newLinkedHashMap(3); > fields.put("id", Long.class.getName()); > fields.put("startDate", Date.class.getName()); > qe.setFields(fields); > QueryIndex idx = new QueryIndex(); > idx.setIndexType(QueryIndexType.SORTED); > LinkedHashMap idxFields = U.newLinkedHashMap(3); > idxFields.put("startDate", Boolean.TRUE); > idx.setFields(idxFields); > qe.setIndexes(Collections.singleton(idx)); > cacheCfg.setQueryEntities(Collections.singleton(qe)); > cfg.setCacheConfiguration(cacheCfg); > return cfg; > } > /** */ > public void testIndexUsageAscSort() { > testIndexUsage0(true); > } > /** */ > public void testIndexUsageDescSort() { > testIndexUsage0(false); > } > /** */ > private void testIndexUsage0(boolean asc) { > Calendar start = Calendar.getInstance(); > start.set(2017, APRIL, 1, 0, 0, 0); > IgniteCache cache = ignite(0).cache(CACHE_NAME); > int step = 50; > for (long i = 0; i < step; i++) { > Date date = start.getTime(); > for (long j = 0; j < step; j++) > cache.put(i * step + j, new IndexedValue(i * step + j, date)); > start.add(Calendar.DAY_OF_MONTH, 1); > } > start.set(2017, APRIL, 10, 0, 0, 0); > Date from = start.getTime(); > start.add(DAY_OF_MONTH, step * step / 2); > int limit = 500; > Date to = start.getTime(); > SqlFieldsQuery q = new SqlFieldsQuery("explain analyze select _KEY, _VAL, startdate " + > "from IndexedValue where startDate >= ? and startDate < ? " + > "order by startdate " + (asc ? "asc" : "desc") + " limit " + limit); > q.setLocal(true); > q.setArgs(from, to); > List> all = cache.query(q).getAll(); > String plan = all.toString(); > final String str = "scanCount: "; > int off = plan.indexOf(str); > assertTrue(off != -1); > off += "scanCount:".length() + 1; > int st = off; > while(Character.isDigit(plan.charAt(off++))); > int scanCnt = Integer.parseInt(plan.substring(st, off - 1)); > assertEquals(limit, scanCnt); > } > /** */ > public static class IndexedValue { > /** */ > private Long id; > /** */ > private Date startDate; > /** > * @param id Id. > * @param startDate Start date. > */ > public IndexedValue(Long id, Date startDate) { > this.id = id; > this.startDate = startDate; > } > /** */ > public Long getId() { > return id; > } > /** */ > public void setId(Long id) { > this.id = id; > } > /** */ > public Date getStartDate() { > return startDate; > } > /** */ > public void setStartDate(Date startDate) { > this.startDate = startDate; > } > } > } > {noformat} -- This message was sent by Atlassian JIRA (v6.4.14#64029)