Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Add explicit hints (#7418)
Browse files Browse the repository at this point in the history
Add explicit NO_INDEX_FFS where Oracle seems sometimes to employ.
  • Loading branch information
CVdV-au authored Nov 1, 2024
1 parent 5c0bb9a commit 3c9ccbf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public FullQuery getLatestRowQuery(byte[] row, long ts, ColumnSelection columns,
@Override
public FullQuery getLatestRowsQuery(Iterable<byte[]> rows, long ts, ColumnSelection columns, boolean includeValue) {
String query = "SELECT"
+ " /*+ USE_NL(t m) LEADING(t m) */ "
+ " /*+ USE_NL(t m) LEADING(t m) NO_INDEX_FFS(m) */ "
+ " m.row_name, m.col_name, max(m.ts) as ts "
+ " FROM " + tableName + " m, TABLE(CAST(? AS " + structArrayPrefix() + "CELL_TS_TABLE)) t "
+ " WHERE m.row_name = t.row_name "
Expand Down Expand Up @@ -115,7 +115,7 @@ public FullQuery getAllRowQuery(byte[] row, long ts, ColumnSelection columns, bo
public FullQuery getAllRowsQuery(Iterable<byte[]> rows, long ts, ColumnSelection columns, boolean includeValue) {
String query = " /* GET_ALL_ROWS_SINGLE_BOUND (" + tableName + ") */ "
+ " SELECT"
+ " /*+ USE_NL(t m) LEADING(t m) */"
+ " /*+ USE_NL(t m) LEADING(t m) NO_INDEX_FFS(m) */"
+ " m.row_name, m.col_name, m.ts" + getValueSubselect("m", includeValue)
+ " FROM " + tableName + " m, TABLE(CAST(? AS " + structArrayPrefix() + "CELL_TS_TABLE)) t "
+ " WHERE m.row_name = t.row_name "
Expand Down Expand Up @@ -149,7 +149,7 @@ public FullQuery getLatestCellQuery(Cell cell, long ts, boolean includeValue) {
@Override
public FullQuery getLatestCellsQuery(Collection<Map.Entry<Cell, Long>> cells, boolean includeValue) {
String query = "SELECT"
+ " /*+ USE_NL(t m) LEADING(t m) */ "
+ " /*+ USE_NL(t m) LEADING(t m) NO_INDEX_FFS(m) */ "
+ " m.row_name, m.col_name, max(m.ts) as ts "
+ " FROM " + tableName + " m, TABLE(CAST(? AS " + structArrayPrefix() + "CELL_TS_TABLE)) t "
+ " WHERE m.row_name = t.row_name "
Expand All @@ -176,7 +176,7 @@ public FullQuery getAllCellQuery(Cell cell, long ts, boolean includeValue) {
public FullQuery getAllCellsQuery(Iterable<Cell> cells, long ts, boolean includeValue) {
String query = " /* GET_ALL_CELLS_SINGLE_BOUND (" + tableName + ") */ "
+ " SELECT"
+ " /*+ USE_NL(t m) LEADING(t m) */ "
+ " /*+ USE_NL(t m) LEADING(t m) NO_INDEX_FFS(m) */ "
+ " m.row_name, m.col_name, m.ts" + getValueSubselect("m", includeValue)
+ " FROM " + tableName + " m, TABLE(CAST(? AS " + structArrayPrefix() + "CELL_TS_TABLE)) t "
+ " WHERE m.row_name = t.row_name "
Expand Down Expand Up @@ -277,7 +277,7 @@ protected FullQuery getRowsColumnRangeSubQuery(
protected FullQuery getRowsColumnRangeFullyLoadedRowsSubQuery(
List<byte[]> rows, long ts, ColumnRangeSelection columnRangeSelection) {
String query = "SELECT"
+ " /*+ USE_NL(t m) LEADING(t m) */"
+ " /*+ USE_NL(t m) LEADING(t m) NO_INDEX_FFS(m) */"
+ " m.row_name, m.col_name, max(m.ts) as ts"
+ " FROM " + tableName + " m, TABLE(CAST(? AS " + structArrayPrefix() + "CELL_TS_TABLE)) t "
+ " WHERE m.row_name = t.row_name "
Expand All @@ -297,15 +297,15 @@ protected FullQuery getRowsColumnRangeFullyLoadedRowsSubQuery(
return fullQuery;
}

private String wrapQueryWithIncludeValue(String wrappedName, String query, boolean includeValue) {
private String wrapQueryWithIncludeValue(String name, String query, boolean includeValue) {
if (!includeValue) {
return query;
return "/* " + name + " (" + tableName + ") */ " + query;
}
return " /* " + wrappedName + " (" + tableName + ") */ "
return "/* " + name + "_VALUE (" + tableName + ") */ "
+ " SELECT"
+ " /*+ USE_NL(i wrap) LEADING(i wrap) NO_MERGE(i) NO_PUSH_PRED(i)"
+ " INDEX(wrap " + PrimaryKeyConstraintNames.get(tableName) + ") */ "
+ " wrap.row_name, wrap.col_name, wrap.ts" + getValueSubselect("wrap", includeValue)
+ " wrap.row_name, wrap.col_name, wrap.ts" + getValueSubselect("wrap", true)
+ " FROM " + tableName + " wrap, ( " + query + " ) i "
+ " WHERE wrap.row_name = i.row_name "
+ " AND wrap.col_name = i.col_name "
Expand Down
7 changes: 7 additions & 0 deletions changelog/@unreleased/pr-7418.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: fix
fix:
description: |-
Add explicit hints, have seen Oracle incorrectly using FAST_FULL_SCAN on very large tables.
Possibly unexpected side effect from https://github.com/palantir/atlasdb/pull/7338 - even though the cardinality hints removed were misleading, they may have made Oracle behave.
links:
- https://github.com/palantir/atlasdb/pull/7418

0 comments on commit 3c9ccbf

Please sign in to comment.