Skip to content

Commit 3c08e16

Browse files
authored
fix(plugin-oracle): Switch to ALL_TAB_* as DBA_TAB* requires ADMIN pe… (#26554)
…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 <!---Describe any public API or user-facing feature change or any performance impact--> ## Test Plan <!---Please fill in how you tested your change--> ## Contributor checklist - [ ] Please make sure your submission complies with our [contributing guide](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md), in particular [code style](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#code-style) and [commit standards](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#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](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines). - [ ] Adequate tests were added if applicable. - [ ] CI passed. - [ ] If adding new dependencies, verified they have an [OpenSSF Scorecard](https://securityscorecards.dev/#the-checks) score of 5.0 or higher (or obtained explicit TSC approval for lower scores). ## Release Notes ``` == NO RELEASE NOTE == ```
1 parent 39403bb commit 3c08e16

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

presto-oracle/src/main/java/com/facebook/presto/plugin/oracle/OracleClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public TableStatistics getTableStatistics(ConnectorSession session, JdbcTableHan
162162
requireNonNull(handle.getTableName(), "table name is null");
163163
String sql = format(
164164
"SELECT NUM_ROWS, AVG_ROW_LEN, LAST_ANALYZED\n" +
165-
"FROM DBA_TAB_STATISTICS\n" +
165+
"FROM ALL_TAB_STATISTICS\n" +
166166
"WHERE OWNER='%s'\n" +
167167
"AND TABLE_NAME='%s'",
168168
handle.getSchemaName().toUpperCase(), handle.getTableName().toUpperCase());
@@ -190,9 +190,12 @@ public TableStatistics getTableStatistics(ConnectorSession session, JdbcTableHan
190190
double lowValue = toDouble(resultSetColumnStats.getString("LOW_VALUE"));
191191
double highValue = toDouble(resultSetColumnStats.getString("HIGH_VALUE"));
192192
ColumnStatistics.Builder columnStatisticsBuilder = ColumnStatistics.builder()
193-
.setDataSize(Estimate.estimateFromDouble(resultSet.getDouble("DATA_LENGTH")))
194193
.setNullsFraction(Estimate.estimateFromDouble(nullsCount / numRows))
195194
.setDistinctValuesCount(Estimate.estimateFromDouble(ndv));
195+
if (resultSetColumnStats.getString("DATA_TYPE").startsWith("VARCHAR") ||
196+
resultSetColumnStats.getString("DATA_TYPE").startsWith("CHAR")) {
197+
columnStatisticsBuilder.setDataSize(Estimate.estimateFromDouble(resultSetColumnStats.getDouble("DATA_LENGTH")));
198+
}
196199
ColumnStatistics columnStatistics = columnStatisticsBuilder.build();
197200
if (Double.isFinite(lowValue) && Double.isFinite(highValue)) {
198201
columnStatistics = columnStatisticsBuilder.setRange(new DoubleRange(lowValue, highValue)).build();

0 commit comments

Comments
 (0)