Skip to content

Commit

Permalink
PHOENIX-1436 the choice of index by phoneix is not correct where do q…
Browse files Browse the repository at this point in the history
…uerying
  • Loading branch information
jtaylor-sfdc committed Nov 22, 2014
1 parent b39f44b commit 78a735e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,6 @@ public int compare(QueryPlan plan1, QueryPlan plan2) {
// indexed columns then give first priority to the local index.
if (!bothLocalIndexes && table1.getIndexType() == IndexType.LOCAL
&& plan1.getContext().getScanRanges().getRanges().isEmpty()) c--;
// if both tables are index tables then select plan below based on number of
// columns and type of index.
if(table1.getType()==PTableType.INDEX && table2.getType()==PTableType.INDEX && !bothLocalIndexes) c=0;
}
if (c != 0) return c;
if (plan1.getGroupBy()!=null && plan2.getGroupBy()!=null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -38,6 +39,7 @@
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.QueryUtil;
import org.apache.phoenix.util.SchemaUtil;
import org.junit.Test;

Expand Down Expand Up @@ -370,6 +372,19 @@ public void testAssertQueryPlanDetails8() throws Exception {
testAssertQueryPlanDetails(false, true, false);
}

@Test
public void testQueryOptimizerShouldSelectThePlanWithMoreNumberOfPKColumns() throws Exception {
Connection conn1 = DriverManager.getConnection(getUrl());
Connection conn2 = DriverManager.getConnection(getUrl());
conn1.createStatement().execute("create table index_test_table (a varchar not null,b varchar not null,c varchar not null,d varchar,e varchar, f varchar constraint pk primary key(a,b,c))");
conn1.createStatement().execute(
"create index INDEX_TEST_TABLE_INDEX_D on INDEX_TEST_TABLE(A,D) include(B,C,E,F)");
conn1.createStatement().execute(
"create index INDEX_TEST_TABLE_INDEX_F on INDEX_TEST_TABLE(A,F) include(B,C,D,E)");
ResultSet rs = conn2.createStatement().executeQuery("explain select * from INDEX_TEST_TABLE where A in ('1','2','3','4','5') and F in ('1111','2222','3333')");
assertEquals("CLIENT PARALLEL 1-WAY SKIP SCAN ON 15 KEYS OVER INDEX_TEST_TABLE_INDEX_F ['1','1111'] - ['5','3333']", QueryUtil.getExplainPlan(rs));
}

private void testAssertQueryPlanDetails(boolean multitenant, boolean useIndex, boolean salted) throws Exception {
String sql;
PreparedStatement stmt;
Expand Down

0 comments on commit 78a735e

Please sign in to comment.