Skip to content

Conversation

@ScrapCodes
Copy link
Contributor

@ScrapCodes ScrapCodes commented Nov 6, 2025

…rmission

Description

https://docs.oracle.com/en/database/oracle/oracle-database/21/refrn/ALL_TAB_STATISTICS.html#GUID-C567F729-3748-4DFE-A22C-115CB7575D63

As per the docs above, DB_TAB_STATISTICS table requires admin privilage, whereas ALL_TAB_STATISTICS returns stats for tables accessible by current user.

Motivation and Context

Fixes a case where user does not have permission on DBA_TAB_STATISTICS table.

Impact

Test Plan

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.
  • If adding new dependencies, verified they have an OpenSSF Scorecard score of 5.0 or higher (or obtained explicit TSC approval for lower scores).

Release Notes

== NO RELEASE NOTE ==

@ScrapCodes ScrapCodes requested a review from a team as a code owner November 6, 2025 14:38
@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Nov 6, 2025
@prestodb-ci prestodb-ci requested review from a team and xin-zhang2 and removed request for a team November 6, 2025 14:38
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 6, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR updates the Oracle connector’s getTableStatistics logic to query ALL_TAB_STATISTICS instead of DBA_TAB_STATISTICS to avoid admin permission requirements, and improves column statistics by conditionally setting data size only for CHAR/VARCHAR types.

ER diagram for change from DBA_TAB_STATISTICS to ALL_TAB_STATISTICS

erDiagram
ALL_TAB_STATISTICS {
  NUM_ROWS int
  AVG_ROW_LEN int
  LAST_ANALYZED date
  OWNER varchar
  TABLE_NAME varchar
}
TableStatistics {
  NUM_ROWS int
  AVG_ROW_LEN int
  LAST_ANALYZED date
}
ALL_TAB_STATISTICS ||--o| TableStatistics : provides
Loading

Class diagram for updated OracleClient.getTableStatistics logic

classDiagram
class OracleClient {
  +getTableStatistics(session, handle)
}
class TableStatistics
class ColumnStatistics {
  +setDataSize(size)
  +setNullsFraction(fraction)
  +setDistinctValuesCount(count)
  +setRange(range)
}
class Estimate {
  +estimateFromDouble(value)
}
class DoubleRange
OracleClient --> TableStatistics
OracleClient --> ColumnStatistics
ColumnStatistics --> Estimate
ColumnStatistics --> DoubleRange
Loading

File-Level Changes

Change Details Files
Use ALL_TAB_STATISTICS instead of DBA_TAB_STATISTICS for table statistics
  • Replaced SQL source in getTableStatistics to SELECT from ALL_TAB_STATISTICS
  • Removed dependency on DBA_TAB_STATISTICS requiring admin privileges
presto-oracle/src/main/java/com/facebook/presto/plugin/oracle/OracleClient.java
Conditionally set data size only for CHAR/VARCHAR columns
  • Removed unconditional setDataSize call
  • Added check for DATA_TYPE starting with CHAR or VARCHAR before setting data size
presto-oracle/src/main/java/com/facebook/presto/plugin/oracle/OracleClient.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ScrapCodes ScrapCodes changed the title fix(presto-plugin): Switch to ALL_TAB_* as DBA_TAB* requires ADMIN pe… fix(presto-oracle): Switch to ALL_TAB_* as DBA_TAB* requires ADMIN pe… Nov 6, 2025
@ScrapCodes ScrapCodes changed the title fix(presto-oracle): Switch to ALL_TAB_* as DBA_TAB* requires ADMIN pe… fix(plugin-oracle): Switch to ALL_TAB_* as DBA_TAB* requires ADMIN pe… Nov 6, 2025
@ScrapCodes
Copy link
Contributor Author

We only propagate varchar/char data size and null for the rest. In a subsequent PR, we could see how to convert presto data sizes corresponding to each oracle type.

presto:default> show stats for myoracle.tm_lakehouse_engine.employee;
         column_name         | data_size | distinct_values_count | nulls_fraction | row_count | low_value | high_value | histogram 
-----------------------------+-----------+-----------------------+----------------+-----------+-----------+------------+-----------
 employee_id_bigint          | NULL      |                  10.0 |            0.0 | NULL      | 1         | 10         | NULL      
 age_tinyint                 | NULL      |                  10.0 |            0.0 | NULL      | 22        | 40         | NULL      
 department_id_smallint      | NULL      |                   3.0 |            0.0 | NULL      | 1         | 3          | NULL      
 years_of_experience_integer | NULL      |                   9.0 |            0.0 | NULL      | 1         | 15         | NULL      
 salary_decimal              | NULL      |                  10.0 |            0.0 | NULL      | 45000.0   | 90000.0    | NULL      
 bonus_double                | NULL      |                  10.0 |            0.0 | NULL      | NULL      | NULL       | NULL      
 performance_rating_real     | NULL      |                  10.0 |            0.0 | NULL      | NULL      | NULL       | NULL      
 first_name_varchar          |     100.0 |                  10.0 |            0.0 | NULL      | NULL      | NULL       | NULL      
 gender_char                 |       1.0 |                   2.0 |            0.0 | NULL      | NULL      | NULL       | NULL      
 height_real                 | NULL      |                   9.0 |            0.0 | NULL      | NULL      | NULL       | NULL      
 full_time                   | NULL      |                   2.0 |            0.0 | NULL      | 0         | 1          | NULL      
 team_head_varchar           |     255.0 |                   3.0 |            0.0 | NULL      | NULL      | NULL       | NULL      
 reference_id_bigint         | NULL      |                   3.0 |            0.0 | NULL      | 1         | 5          | NULL      
 NULL                        | NULL      | NULL                  | NULL           |      10.0 | NULL      | NULL       | NULL      
(14 rows)

Query 20251106_151439_00000_ijn7e, FINISHED, 1 node
Splits: 1 total, 1 done (100.00%)
[Latency: client-side: 0:13, server-side: 0:12] [0 rows, 0B] [0 rows/s, 0B/s]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants