Hi With using phoenix-4.8.1-HBase-1.1-bin I have problems doing a join with hints.
Doing a select with a join on two tables when trying to use multiple hints phoenix does include them in the execution plan: Should be: CLIENT 1-CHUNK 0 ROWS 0 BYTES PARALLEL 1-WAY ROUND ROBIN RANGE SCAN OVER C12_SIDR_CDR_20160820_INDEX ['293400115278890'] ) For example: SELECT /*+ INDEX(SIDR_CDR_20160820 c12_SIDR_CDR_20160820_INDEX), USE_SORT_MERGE_JOIN */ crm.c5, crm.c6,crm.c7, crm.c10, crm.c11, cdr.c2, cdr.c4, cdr.c7, cdr.c8, cdr.c9, cdr.c10, cdr.c11, cdr.c12, cdr.c5, cdr.c6, cdr.c19, cdr.c20, cdr.c15, cdr.c16, cdr.c13, cdr.c5 FROM SIDR_CDR_20160820 cdr, SIDR_CRM crm WHERE ((cdr.c8 IN (1, 130, 29, 3, 2, 131, 31, 132, 30, 133, 136, 137, 135, 134, 150)) AND (cdr.c12 = '293400115278890')) AND (cdr.c2 <= TO_DATE('20.08.2016 23:59:59', 'dd.MM.yyyy HH:mm:ss')) AND crm.c1 = '0' || SUBSTR(cdr.c5, 4) AND cdr.c2 >= crm.c2 AND (cdr.c2 < crm.c3 OR crm.c3 IS NULL); +----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | SORT-MERGE-JOIN (INNER) TABLES | | CLIENT 794-CHUNK 41607713 ROWS 20709402545 BYTES PARALLEL 794-WAY FULL SCAN OVER SIDR_CDR_20160820 | | SERVER FILTER BY (C8 IN (1,2,3,29,30,31,130,131,132,133,134,135,136,137,150) AND C12 = '293400115278890' AND C2 <= TIMESTAMP '2016-08-20 23:59:59.000' | | SERVER SORTED BY [('0' || SUBSTR(CDR.C5, 4, null))] | | CLIENT MERGE SORT | | AND | | CLIENT 35-CHUNK 1864177 ROWS 865075995 BYTES PARALLEL 1-WAY FULL SCAN OVER SIDR_CRM | | CLIENT FILTER BY (CDR.C2 >= CRM.C2 AND (CDR.C2 < CRM.C3 OR CRM.C3 IS NULL)) | +----------------------------------------------------------------------------------------------------------------------------------------------------------------+ When further investigating this, phoenix I think has two errors: 1. This is a query without a join only selecting from SIDR_CDR_20160820 cdr. I am not able to mix a real table name (for hints) and synonime (for select), the second query has the correct execution plan explain SELECT /*+ INDEX(SIDR_CDR_20160820 c12_SIDR_CDR_20160820_INDEX)*/ cdr.c2, cdr.c4, cdr.c7, cdr.c8, cdr.c9, cdr.c10, cdr.c11, cdr.c12, cdr.c5, cdr.c6, cdr.c19, cdr.c20, cdr.c15, cdr.c16, cdr.c13, cdr.c5 FROM SIDR_CDR_20160820 cdr WHERE ((cdr.c8 IN (1, 130, 29, 3, 2, 131, 31, 132, 30, 133, 136, 137, 135, 134, 150)) AND (cdr.c12 = '293400115278890')) AND (cdr.c2 <= TO_DATE('20.08.2016 23:59:59', 'dd.MM.yyyy HH:mm:ss')); +----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | CLIENT 794-CHUNK 41607713 ROWS 20709402545 BYTES PARALLEL 1-WAY ROUND ROBIN FULL SCAN OVER SIDR_CDR_20160820 | | SERVER FILTER BY ((C8 IN (1,2,3,29,30,31,130,131,132,133,134,135,136,137,150) AND C12 = '293400115278890') AND C2 <= TIMESTAMP '2016-08-20 23:59:59.000') | +----------------------------------------------------------------------------------------------------------------------------------------------------------------+ A correct execution plan with the same query only with a changed hint /*+ INDEX(cdr c12_SIDR_CDR_20160820_INDEX)*/ 0: jdbc:phoenix:lxdr1> explain SELECT /*+ INDEX(cdr c12_SIDR_CDR_20160820_INDEX)*/ cdr.c2, cdr.c4, cdr.c7, cdr.c8, cdr.c9, cdr.c10, cdr.c11, cdr.c12, cdr.c5, cdr.c6, cdr.c19, cdr.c20, cdr.c15, cdr.c16, cdr.c13, cdr.c5 FROM SIDR_CDR_20160820 cdr WHERE ((cdr.c8 IN (1, 130, 29, 3, 2, 131, 31, 132, 30, 133, 136, 137, 135, 134, 150)) AND (cdr.c12 = '293400115278890')) AND (cdr.c2 <= TO_DATE('20.08.2016 23:59:59', 'dd.MM.yyyy HH:mm:ss')); +-----------------------------------------------------------------------------------------------------------------------------------+ | PLAN | +-----------------------------------------------------------------------------------------------------------------------------------+ | CLIENT 794-CHUNK 41607713 ROWS 20709402545 BYTES PARALLEL 1-WAY ROUND ROBIN FULL SCAN OVER SIDR_CDR_20160820 | | SERVER FILTER BY C8 IN (1,2,3,29,30,31,130,131,132,133,134,135,136,137,150) | | SKIP-SCAN-JOIN TABLE 0 | | CLIENT 1-CHUNK 0 ROWS 0 BYTES PARALLEL 1-WAY ROUND ROBIN RANGE SCAN OVER C12_SIDR_CDR_20160820_INDEX ['293400115278890'] | | SERVER FILTER BY FIRST KEY ONLY AND "C2" <= TIMESTAMP '2016-08-20 23:59:59.000' | | DYNAMIC SERVER FILTER BY ("CDR.C1", "CDR.C2", "CDR.C3", "CDR.C4") IN (($422.$424, $422.$425, $422.$426, $422.$427)) | +-----------------------------------------------------------------------------------------------------------------------------------+ 2. Phoenix throws an exception parsing two hints at least with a join: The hint SELECT /*+ INDEX(cdr c12_SIDR_CDR_20160820_INDEX), USE_SORT_MERGE_JOIN */ 0: jdbc:phoenix:lxdr1> explain SELECT /*+ INDEX(cdr c12_SIDR_CDR_20160820_INDEX), USE_SORT_MERGE_JOIN */ crm.c5, crm.c6,crm.c7, crm.c10, crm.c11, cdr.c2, cdr.c4, cdr.c7, cdr.c8, cdr.c9, cdr.c10, cdr.c11, cdr.c12, cdr.c5, cdr.c6, cdr.c19, cdr.c20, cdr.c15, cdr.c16, cdr.c13, cdr.c5 FROM SIDR_CDR_20160820 cdr, SIDR_CRM crm WHERE ((cdr.c8 IN (1, 130, 29, 3, 2, 131, 31, 132, 30, 133, 136, 137, 135, 134, 150)) AND (cdr.c12 = '293400115278890')) AND (cdr.c2 <= TO_DATE('20.08.2016 23:59:59', 'dd.MM.yyyy HH:mm:ss')) AND crm.c1 = '0' || SUBSTR(cdr.c5, 4) AND cdr.c2 >= crm.c2 AND (cdr.c2 < crm.c3 OR crm.c3 IS NULL); java.lang.NullPointerException at org.apache.phoenix.parse.IndexExpressionParseNodeRewriter.<init>(IndexExpressionParseNodeRewriter.java:43) at org.apache.phoenix.compile.JoinCompiler.optimize(JoinCompiler.java:1250) at org.apache.phoenix.compile.QueryCompiler.compileSelect(QueryCompiler.java:194) at org.apache.phoenix.compile.QueryCompiler.compile(QueryCompiler.java:157) at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableSelectStatement.compilePlan(PhoenixStatement.java:406) at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableSelectStatement.compilePlan(PhoenixStatement.java:380) at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableExplainStatement.compilePlan(PhoenixStatement.java:465) at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableExplainStatement.compilePlan(PhoenixStatement.java:445) at org.apache.phoenix.jdbc.PhoenixStatement$1.call(PhoenixStatement.java:271) at org.apache.phoenix.jdbc.PhoenixStatement$1.call(PhoenixStatement.java:266) at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53) at org.apache.phoenix.jdbc.PhoenixStatement.executeQuery(PhoenixStatement.java:265) at org.apache.phoenix.jdbc.PhoenixStatement.execute(PhoenixStatement.java:1446) at sqlline.Commands.execute(Commands.java:822) at sqlline.Commands.sql(Commands.java:732) at sqlline.SqlLine.dispatch(SqlLine.java:807) at sqlline.SqlLine.begin(SqlLine.java:681) at sqlline.SqlLine.start(SqlLine.java:398) at sqlline.SqlLine.main(SqlLine.java:292) I will appreciate any help. Regards, Gasper