com.pivotal.gemfirexd.internal.engine.distributed.metadata.ColocationCriteria Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snappydata-store-core Show documentation
Show all versions of snappydata-store-core Show documentation
TIBCO ComputeDB store based off Pivotal GemFireXD
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* Licensed 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. See accompanying
* LICENSE file.
*/
package com.pivotal.gemfirexd.internal.engine.distributed.metadata;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.ListIterator;
import java.util.Map;
import com.gemstone.gemfire.internal.cache.PartitionedRegion;
import com.gemstone.gnu.trove.THashSet;
import com.gemstone.gnu.trove.TIntIntHashMap;
import com.pivotal.gemfirexd.internal.engine.GemFireXDQueryObserver;
import com.pivotal.gemfirexd.internal.engine.GemFireXDQueryObserverHolder;
import com.pivotal.gemfirexd.internal.engine.ddl.resolver.GfxdPartitionResolver;
import com.pivotal.gemfirexd.internal.iapi.sql.dictionary.ColumnDescriptor;
/**
* This class enacpsulates the logic of identifying if a multi table query has
* colocated equijoin criteria satisfied.
*
* @author Asif
* @author swale
*/
public final class ColocationCriteria {
/* Array of Set where each element corresponds to a partitioning column.
* The Set would contain the Table Position for the partitioning column which acts as
* a tying node across the equi join conditions. The number of such unqiue tying nodes
* will be Number of Tables - 2.
* The number of equi join conditions needed will be Number Of Tables -1.
*
* For eg if we have 3 tables & 3 partitioning cols
* T1 T2 T3
* a a1 a2 a3
* b b1 b2 b3
* c c1 c2 c3
*
* we will need in total 2*3 conditions
* a1 = b2 a2 = b3
* b1 = a2 b2 = a3
* c1 = c2 c2 = c3
*
* Here number of tying nodes = 3 -2 = 1
* For a , a2 is the tying node ( pos 2)
* For b , b2 is the tying node
* For C , c2 is the tying node
*
* [sumedh] (Change in implementation):
* The older technique will not work for many cases like a common
* node being common to more than 2 nodes, extraneous conditions (repeated
* conditions are now checked). Updating to a new technique that will handle
* all such cases as well as replicated tables and constants after minor
* extensions thus: For each equijoin condition we assign a distinct value
* to the rhs. This value will then be copied to lhs as the equality says.
* In the end we need to ensure that all columns of each table have all
* distinct values. If we encounter a column that already has a value
* assigned then the two values must be made identical. For implementation
* we let the values be indices into an array of Integer objects. When
* this case is encountered then the references of the two Integer objects
* are made identical.
*/
/**
* This list contains the actual values for the indices assigned in the
* colocation matrix.
*/
private final ArrayList indexValueList;
/** current value of the index of the indexValueList */
private int currentIndex;
/**
* ArrayList used to store the TableQueryInfo's for each table which is used
* to skip the {@link #isEquiJoinColocationCriteriaFullfilled} for replicated
* tables.
*/
private final ArrayList tableQueryInfos;
/*
* The columns correspond to the number of tables involved
* The rows correspond to the number of partitioning columns
* If the partitioning columns are a,b,c
* T1 T2 T3 T4
* a
* b
* c
* A value in a cell indicates the index into the indexValueList
* (starting with 1) that has been assigned to both lhs and rhs
* of an equality condition.
*/
private final Map