aws / aws/amazon-redshift-jdbc-driver

Prepared statement SELECT tablename FROM SVV_EXTERNAL_TABLES with setFetchSize gives ERROR: portal "c_6-16720547611010" does not exist if number of rows exceeds fetch size

Open
#80 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
71
Forks
42
PR merge metrics
No merged PRs in 30d

Description

## Driver version
2.1.0.10

## Redshift version
PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.44903

## Client Operating System
UBI8

## JAVA/JVM version
openjdk version "17.0.5" 2022-10-18

## Problem description
1. Expected behaviour:
You should be able to use PreparedStatements with a fetchSize less than the number of rows in the svv_external_tables.

2. Actual behaviour:
If the svv_external_tables number of rows exceeds the fetch size then the portal does not exist issue happens like in: https://github.com/aws/amazon-redshift-jdbc-driver/issues/9

3. Error message/stack trace:
`
Exception in thread "main" java.lang.RuntimeException: Failed to read row: ERROR: portal "c_6-16720547611010" does not exist
`
4. Any other details that can be helpful:
`
enableFetchRingBuffer=false
`
fetchSize needs to be less than than the number of rows in the svv_external_tables
Statement still works fine.
Same thing happens when querying SELECT tablename FROM pg_tables

## Reproduction code
`
String query = "SELECT tablename FROM SVV_EXTERNAL_TABLES"; // where svv_external_tables has more than 500 rows
PreparedStatement statement = c.prepareStatement(query);
statement.setFetchSize(500);

try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
System.out.println(resultSet.getString(1));
}
}
`

Contributor guide

Open the contributing guide

Research direction

Start with the Java reproduction using a PreparedStatement, setFetchSize(500), and the SVV_EXTERNAL_TABLES query, then compare it with the working Statement behavior and the pg_tables case. Done means iterating through more rows than the fetch size without the portal-not-exist error, including with enableFetchRingBuffer=false.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.