Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated getIndexInfo() to include Columnstore indexes by using custom query. #2566

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Ananya2
Copy link
Contributor

@Ananya2 Ananya2 commented Dec 17, 2024

Replaced the use of the sp_statistics stored procedure with a custom query to retrieve index information as the sp_statistics procedure did not return Columnstore indexes, so a query using sys.indexes was implemented as a workaround.
This new query ensures that all index types (Clustered, NonClustered, Columnstore) are included in the result set.
Github Issue: #2546

Copy link

codecov bot commented Dec 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.06%. Comparing base (6829848) to head (420b583).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2566      +/-   ##
============================================
+ Coverage     51.03%   51.06%   +0.02%     
- Complexity     3919     3921       +2     
============================================
  Files           147      147              
  Lines         33456    33445      -11     
  Branches       5604     5602       -2     
============================================
+ Hits          17074    17078       +4     
+ Misses        13971    13956      -15     
  Partials       2411     2411              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

arguments[5] = "E";
return getResultSetWithProvidedColumnNames(cat, CallableHandles.SP_STATISTICS, arguments,
getIndexInfoColumnNames);
String query = "SELECT " +
Copy link

Choose a reason for hiding this comment

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

Can we use StringBuilder instead of String for concatenation?

@Override
public java.sql.ResultSet getIndexInfo(String cat, String schema, String table, boolean unique,
boolean approximate) throws SQLServerException, SQLTimeoutException {
boolean approximate) throws SQLServerException, SQLTimeoutException, SQLException {
Copy link

Choose a reason for hiding this comment

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

Adding a comments to explain the rationale behind replacing the stored procedure call with a direct SQL query.

@Override
public java.sql.ResultSet getIndexInfo(String cat, String schema, String table, boolean unique,
boolean approximate) throws SQLServerException, SQLTimeoutException {
boolean approximate) throws SQLServerException, SQLTimeoutException, SQLException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove SQLServerException and SQLTimeoutException (more general SQLException covers both).

Suggested change
boolean approximate) throws SQLServerException, SQLTimeoutException, SQLException {
boolean approximate) throws SQLException {

private static String col3Name = AbstractSQLGenerator.escapeIdentifier( "p3");

@BeforeAll
public static void setupTests() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

Try to use the most specific exception possible - replace Exception on lines 29 and 34 with SQLException.

@@ -0,0 +1,174 @@
package com.microsoft.sqlserver.jdbc.databasemetadata;

import static org.junit.jupiter.api.Assertions.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

Use specific imports.

Suggested change
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;


public class DatabaseMetadataGetIndexInfoTest extends AbstractTest {

private static String tableName = AbstractSQLGenerator.escapeIdentifier("DBMetadataTestTable");
Copy link
Contributor

Choose a reason for hiding this comment

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

Run through formatter.


stmt.executeUpdate(createTableSQL);
assertNull(connection.getWarnings(), "Expecting NO SQLWarnings from 'create table', at Connection.");
assertNull(stmt.getWarnings(), "Expecting NO SQLWarnings from 'create table', at Statement.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Because these messages are used several times, can each of the Connection and Statement messages be placed in TestResource instead?

}

@Test
public void testGetIndexInfo() throws SQLException, SQLServerException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Exception not needed.

Suggested change
public void testGetIndexInfo() throws SQLException, SQLServerException {
public void testGetIndexInfo() throws SQLException {

String indexType = rs1.getString("IndexType");
String indexName = rs1.getString("IndexName");

assertEquals(rs1.getString("CatalogName"), rs2.getString("CatalogName"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add all these strings to Constants?

}

@Test
public void testGetIndexInfoCaseSensitivity() throws SQLException, SQLServerException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Exception not needed.

Suggested change
public void testGetIndexInfoCaseSensitivity() throws SQLException, SQLServerException {
public void testGenIndexInfoCaseSensitivity() throws SQLException {

@Test
public void testGetIndexInfoCaseSensitivity() throws SQLException, SQLServerException {
ResultSet rs1, rs2 = null;
try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Never used.

Suggested change
try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) {
try (Connection connection = getConnection()) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

DatabaseMetaData getIndexInfo does not include COLUMNSTORE Indexes
3 participants