[ 
https://issues.apache.org/jira/browse/PHOENIX-3005?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15338662#comment-15338662
 ] 

James Taylor commented on PHOENIX-3005:
---------------------------------------

Looks to be working fine. The index is used as expected. Here's a couple of 
tests I dropped into QueryOptimizerTest that pass:
{code}
    @Test
    public void testDistinctPrefixOnVarcharIndex() throws Exception {
        Connection conn = DriverManager.getConnection(getUrl());
        conn.createStatement().execute("CREATE TABLE t (k INTEGER NOT NULL 
PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
        conn.createStatement().execute("CREATE INDEX idx ON t(v1)");
        PhoenixStatement stmt = 
conn.createStatement().unwrap(PhoenixStatement.class);
        QueryPlan plan = stmt.optimizeQuery("SELECT COUNT(DISTINCT v1) FROM t");
        assertTrue(plan.getGroupBy().isOrderPreserving());
        assertEquals("IDX", 
plan.getTableRef().getTable().getTableName().getString());
    }

    @Test
    public void testDistinctPrefixOnIntIndex() throws Exception {
        Connection conn = DriverManager.getConnection(getUrl());
        conn.createStatement().execute("CREATE TABLE t (k INTEGER NOT NULL 
PRIMARY KEY, v1 INTEGER, v2 VARCHAR)");
        conn.createStatement().execute("CREATE INDEX idx ON t(v1)");
        PhoenixStatement stmt = 
conn.createStatement().unwrap(PhoenixStatement.class);
        QueryPlan plan = stmt.optimizeQuery("SELECT COUNT(DISTINCT v1) FROM t");
        assertTrue(plan.getGroupBy().isOrderPreserving());
        assertEquals("IDX", 
plan.getTableRef().getTable().getTableName().getString());
    }
{code}
Note that it will compile the query twice - the first time against the data 
table where it will not be order preserving, and the second time against the 
index table where it will be. Are you seeing something different, [~lhofhansl]?

> Use DistinctPrefixFilter for DISTINCT index scans
> -------------------------------------------------
>
>                 Key: PHOENIX-3005
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-3005
>             Project: Phoenix
>          Issue Type: Sub-task
>            Reporter: Lars Hofhansl
>             Fix For: 4.8.0
>
>
> Currently the optimization in PHOENIX-258 is not used for DISTINCT index 
> scans. We should add that as well.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to