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

Can not query the new added column #22824

Closed
a1104321118 opened this issue Dec 12, 2022 · 7 comments
Closed

Can not query the new added column #22824

a1104321118 opened this issue Dec 12, 2022 · 7 comments

Comments

@a1104321118
Copy link

a1104321118 commented Dec 12, 2022

Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details.
If no response anymore and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use?

5.1.0

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-JDBC

Expected behavior

select results contains the column which added just now.

Actual behavior

Not contains.

Reason analyze (If you can)

  1. org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource#contextManager
    this parameter cached the table scheam, column names and others, but when add a new column, it is not changed.
    Or is any config wrong in my code ?
public DataSource shardingDataSource() throws SQLException {
        Map<String, DataSource> dataSourceMap = new HashMap<>(1);
        String datasourceName = "ds0";

        dataSourceMap.put(datasourceName, dataSource());

        
        ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
        shardingRuleConfig.setShardingAlgorithms(ShardingConfig.ALGORITHM_MAP);
        shardingRuleConfig.setTables(ShardingConfig.getAllConfig());

        Properties properties = new Properties();
//        properties.put("sql-show", "true");

        ModeConfiguration modeConfiguration = new ModeConfiguration("Memory", null, true);
        

        return ShardingSphereDataSourceFactory.createDataSource(modeConfiguration, dataSourceMap,
            Collections.singletonList(shardingRuleConfig), properties);
    }

2.org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSetMetaData#getColumnCount

@Override
    public int getColumnCount() throws SQLException {
        if (sqlStatementContext instanceof SelectStatementContext) {
            if (hasSelectExpandProjections()) {
                // there will return n (not include the new column)
                return ((SelectStatementContext) sqlStatementContext).getProjectionsContext().getExpandProjections().size();
            }
            // there will return n+1 (include the new column)
            return resultSetMetaData.getColumnCount();
        }
        return resultSetMetaData.getColumnCount();
    }

3.org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ShorthandProjection#actualColumns

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

  1. create a new table, and query it.(Use Sharding-JDBC,sql use select *)
  2. add a new column. (alter table table add column new_column varchar(255))
  3. re-query it.(Use Sharding-JDBC,sql use select *, do not restart the app)
  4. if the app not restart(to ensure the cache not re-build or refresh), jdbc will return all columns, but sharding-jdbc will not mapping the new_column)

Example codes for reproduce this issue (such as a github link).

@azexcy
Copy link
Contributor

azexcy commented Dec 12, 2022

@TeslaCN Could you help to have a look this issue?

@TeslaCN
Copy link
Member

TeslaCN commented Dec 12, 2022

This is expected behavior. It's recommended to deploy ShardingSphere-JDBC and ShardingSphere-Proxy using cluster mode. Executing DDL to database directly will cause metadata inconsistency.

@a1104321118
Copy link
Author

This is expected behavior. It's recommended to deploy ShardingSphere-JDBC and ShardingSphere-Proxy using cluster mode. Executing DDL to database directly will cause metadata inconsistency.

It means when I use sharding-jdbc and select *, I can not add or drop column when not researt the app ?

Is there has any infterface / chance to update the metadata cache ?

@TeslaCN
Copy link
Member

TeslaCN commented Dec 12, 2022

This is expected behavior. It's recommended to deploy ShardingSphere-JDBC and ShardingSphere-Proxy using cluster mode. Executing DDL to database directly will cause metadata inconsistency.

It means when I use sharding-jdbc and select *, I can not add or drop column when not researt the app ?

Is there has any infterface / chance to update the metadata cache ?

Using Cluster mode could hot reload metadata. There is no such reload method in ShardingSphere-JDBC public API.

@a1104321118
Copy link
Author

This is expected behavior. It's recommended to deploy ShardingSphere-JDBC and ShardingSphere-Proxy using cluster mode. Executing DDL to database directly will cause metadata inconsistency.

It means when I use sharding-jdbc and select *, I can not add or drop column when not researt the app ?
Is there has any infterface / chance to update the metadata cache ?

Using Cluster mode could hot reload metadata. There is no such reload method in ShardingSphere-JDBC public API.

Thanks,By the way,Do you have recommand document for shardingsphere 5.x ? I Have read official doc, But It is not helpful for me. For example, I can not find useful message about ModeConfiguration

@TeslaCN TeslaCN closed this as completed Jan 17, 2023
@a1104321118
Copy link
Author

a1104321118 commented Jan 17, 2023 via email

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

No branches or pull requests

3 participants