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

Remove dead DBKVS code, fix Oracle hints #7338

Merged
merged 3 commits into from
Oct 28, 2024
Merged

Conversation

CVdV-au
Copy link
Contributor

@CVdV-au CVdV-au commented Oct 10, 2024

==COMMIT_MSG==
Oracle hints/query improved; dead DBKVS code removed
==COMMIT_MSG==

Priority:
High, see #pds-594762

@changelog-app
Copy link

changelog-app bot commented Oct 10, 2024

Generate changelog in changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Oracle hints/query improved; dead DBKVS code removed

Check the box to generate changelog(s)

  • Generate changelog entry

@@ -28,27 +28,18 @@ public interface DbQueryFactory {

FullQuery getLatestRowsQuery(Iterable<byte[]> rows, long ts, ColumnSelection columns, boolean includeValue);

FullQuery getLatestRowsQuery(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods are all unused, so deleted from this interface and the Postgres/Oracle implementation classes.

+ " SELECT"
+ " /*+ USE_NL(t m) LEADING(t m) CARDINALITY(t 1) CARDINALITY(m 10) INDEX(m "
+ PrimaryKeyConstraintNames.get(tableName) + ") */ "
String query = "SELECT"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the hints here are simply wrong - there is no table alias t.

More generally:

  1. Hints of the form INDEX(alias PrimaryKeyConstraintNames.get(tableName)) are redundant because in the Oracle implementation of DBKVS, all these tables are Index Organised Tables (IOT) for which the only access is via the index (caveat being if there were secondary indexes on the non-key columns of the IOT we wanted to use such a hint could make sense - but there are not). Specifying an INDEX hint doesn't preclude Oracle from using a non-ideal scan method eg fast full scan, range scan etc) - it just says use this particular index. So these hints provide no utility whatsoever.

  2. Where we have USE_NL(t m) LEADING (t m) we are providing a verify specific access pathway that can only be interpreted one way. The CARDINALITY hints are thus redundant (these provide Oracle with expected counts from each table) because they would normally be fed to the optimiser to help it formulate a plan. But since we've stipulated a plan with USE_NL/LEADING, the cardinality is irrelevant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I imagine the t m references are probably copied from somewhere, but you're right, they don't make sense here.

Confirmed that:

  • we use ORGANIZATION INDEX in creating the tables (OracleDdlTable:285)
  • on that basis, the INDEX hint on the primary key index is redundant
  • for this query, there is no join/product to speak of, so USE_NL and LEADING don't make sense.

@@ -373,15 +276,16 @@ protected FullQuery getRowsColumnRangeSubQuery(
@Override
protected FullQuery getRowsColumnRangeFullyLoadedRowsSubQuery(
List<byte[]> rows, long ts, ColumnRangeSelection columnRangeSelection) {
String query = " /* GET_ROWS_COLUMN_RANGE_FULLY_LOADED_ROWS (" + tableName + ") */ "
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't duplicate the query "name" - the wrapQueryWithIncludeValue wraps these inner queries, and we only need to specify the name there - once.

@@ -373,15 +276,16 @@ protected FullQuery getRowsColumnRangeSubQuery(
@Override
protected FullQuery getRowsColumnRangeFullyLoadedRowsSubQuery(
List<byte[]> rows, long ts, ColumnRangeSelection columnRangeSelection) {
String query = " /* GET_ROWS_COLUMN_RANGE_FULLY_LOADED_ROWS (" + tableName + ") */ "
+ "SELECT * FROM ( SELECT m.row_name, m.col_name, max(m.ts) as ts"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant outer select, ie:
SELECT * FROM (X) -> X

+ " WHERE m.row_name = t.row_name "
+ " AND m.ts < ? "
String query = "SELECT"
+ " /*+ USE_NL(t m) LEADING(t m) */"
Copy link
Contributor Author

@CVdV-au CVdV-au Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this hint where there was not one. In response to issue seen on #pds-594762 where we observed a plan:
image (7)
rather than the expected/sensible form:

               Operation                 |             Options              |            Object Name           | Cardinality  |    Bytes     |     Cost
---------------------------------------- | -------------------------------- | -------------------------------- | ------------ | ------------ | ------------
SELECT STATEMENT                         |                                  |                                  |            0 |            0 |         1959
 SORT                                    | ORDER BY                         |                                  |         1627 |       109009 |         1959
  NESTED LOOPS                           |                                  |                                  |         1627 |       109009 |         1959
   VIEW                                  |                                  |                                  |         1627 |        47183 |          330
    HASH                                 | GROUP BY                         |                                  |         1627 |        39048 |          330
     NESTED LOOPS                        |                                  |                                  |         1627 |        39048 |          329
      COLLECTION ITERATOR                | PICKLER FETCH                    |                                  |          100 |          200 |           29
      INDEX                              | RANGE SCAN                       | PK_PT_MET_OBJ_PARENT_LINKS_ACL   |           16 |          352 |            3
   INDEX                                 | UNIQUE SCAN                      | PK_PT_MET_OBJ_PARENT_LINKS_ACL   |            1 |           38 |            2

@berler
Copy link
Contributor

berler commented Oct 11, 2024

I've confirmed that our internal products that actually use oracle still compile with this change. +1 to removing unused methods.

The other changes also look correct to me.

@jeremyk-91
Copy link
Contributor

Apologies for the delay here, team has been beleaguered with some brutal support issues last week. Picking this back up on my end...

Copy link
Contributor

@jeremyk-91 jeremyk-91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks for submitting this!

I confirmed that outside of the specific query we looked at in getRowsColumnRangeFullyLoadedRowsSubQuery where we added the USE_NL and LEADING hints, all other changes to queries were one of

  • removing INDEX from queries on an IOT table
  • removing CARDINALITY from queries that have USE_NL and LEADING
  • removing "names" from queries that already are wrapped in named queries in only one possible way
  • removing USE_NL and LEADING from queries that don't actually have a join

+ " SELECT"
+ " /*+ USE_NL(t m) LEADING(t m) CARDINALITY(t 1) CARDINALITY(m 10) INDEX(m "
+ PrimaryKeyConstraintNames.get(tableName) + ") */ "
String query = "SELECT"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I imagine the t m references are probably copied from somewhere, but you're right, they don't make sense here.

Confirmed that:

  • we use ORGANIZATION INDEX in creating the tables (OracleDdlTable:285)
  • on that basis, the INDEX hint on the primary key index is redundant
  • for this query, there is no join/product to speak of, so USE_NL and LEADING don't make sense.

+ " /*+ USE_NL(t m) LEADING(t m) CARDINALITY(t 1) CARDINALITY(m 10) INDEX(m "
+ PrimaryKeyConstraintNames.get(tableName) + ") */ "
String query = "SELECT"
+ " /*+ USE_NL(t m) LEADING(t m) */ "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cardinality hint from above.

@bulldozer-bot bulldozer-bot bot merged commit 0dfdd21 into develop Oct 28, 2024
21 checks passed
@bulldozer-bot bulldozer-bot bot deleted the cvdv_au/pds-594762 branch October 28, 2024 22:14
@autorelease3
Copy link

autorelease3 bot commented Oct 28, 2024

Released 0.1181.0

@CVdV-au CVdV-au mentioned this pull request Nov 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants