Skip to content
New issue

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

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

Already on GitHub? # to your account

Optimization of table metadata initialization #1951

Closed
2 tasks done
tristaZero opened this issue Mar 1, 2019 · 7 comments
Closed
2 tasks done

Optimization of table metadata initialization #1951

tristaZero opened this issue Mar 1, 2019 · 7 comments

Comments

@tristaZero
Copy link
Contributor

tristaZero commented Mar 1, 2019

To make start up of ShardingSphere faster, we will do the following improvements:

  • Only load one sharding table meta data into ShardingSphere.
  • Instead of table structures, only table names from default data source will be loaded.

This issue is related with #1933.

@zhang98722
Copy link

i meet the same issue
its cost too much time to load too many default tables like 5000+
i just make the initializer skipped load the default table meta data by only create new
dont know what would happen
and the switch check.table.metadata.enabled cant solve this issue

    public TableMetaData load(final String logicTableName, final ShardingRule shardingRule) throws SQLException {
        if(!isCheckingMetaData){
            return new TableMetaData(new ArrayList<ColumnMetaData>());
        }
        List<TableMetaData> actualTableMetaDataList = load(getDataNodeGroups(logicTableName, shardingRule), shardingRule.getShardingDataSourceNames());
        checkUniformed(logicTableName, actualTableMetaDataList);
        return actualTableMetaDataList.iterator().next();
    }

@tristaZero

@terrymanu terrymanu removed this from the 4.0.0-RC2 milestone Jun 20, 2019
@wgy8283335
Copy link
Contributor

@tristaZero @terrymanu. Does this issue still need a volunteer?

@cbbaaa1989
Copy link

can lazyload sharding table meta data?not load all table meta data on start

@cbbaaa1989
Copy link

@wgy8283335 did you have fixed this issue already?

@daiduan
Copy link

daiduan commented Aug 29, 2019

@tristaZero Hello, I am using shardingsphere3.1.0. In #1944, it has solved the problem of not loading the schema when loading all the tables, but it also does not consider the schema when loading all the columns of the table in TableMetaDataLoader. When using the oracle database, if the oracle user has multiple schema view permissions, it will get all the columns of the same name table, it will also make the system start slower.

private List<ColumnMetaData> getColumnMetaDataList(final Connection connection, final String catalog, final String actualTableName) throws SQLException {
        List<ColumnMetaData> result = new LinkedList<>();
        Collection<String> primaryKeys = getPrimaryKeys(connection, catalog, actualTableName);
        try (ResultSet resultSet = connection.getMetaData().getColumns(catalog, null, actualTableName, null)) {
            while (resultSet.next()) {
                String columnName = resultSet.getString("COLUMN_NAME");
                String columnType = resultSet.getString("TYPE_NAME");
                result.add(new ColumnMetaData(columnName, columnType, primaryKeys.contains(columnName)));
            }
        }
        return result;
    }

Is it possible to add connection.getSchema() as the second parameter in getColumns as well?

@terrymanu
Copy link
Member

@daiduan

Is it possible to add connection.getSchema() as the second parameter in getColumns as well?

you may have a try

@daiduan
Copy link

daiduan commented Sep 24, 2019

@terrymanu Yes, I tried. And the system startup speed is getting faster. Now, in our project, we skip some code about init table metadata. I have not found any effect on the system running.

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

No branches or pull requests

6 participants