[CALCITE-6728] Introduce new methods to lookup tables and schemas inside schemas #4100
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
For databases with a huge set of schemas and tables it takes quite long to prepare queries. Currently all tables/schemas are loaded into memory.
Caching all these schemas and tables is not an option
Therefore, we tried to find a way to load only those tables/schemas, which are required to prepare a query.
API Changes
This PR introduces a new mechanism to lookup tables and schemas within a schema. For this purpose a new interface is introduced
The
LikePattern
was extracted fromCalciteMetaImpl
to hold a pattern, which can be used to query tables and schemas inside a JDBC database using theLIKE
operator. Additionally, it also supports the conversion to aPredicate1<String>
which can be used to implement filters in plain java.The
Schema
is now using thisLookup
interface to find schemas and tables. It could be also extended to functions and types.Implementation
The case insensitive search is now directly implemented in the specific
Schema
using matching implementation of theLookup
interface. Formerly, it was done in theCalciteSchema
.JdbcSchema
andJdbcCatalogSchema
are using a special implementation ofLookup
:LoadingCacheLookup
. This implementation is using aLoadingCache
inside to speed up things. If only case sensitive schema/table lookup is required, this can be done quite fast sinceDatabaseMetaData#getTables
can be used to query a single table. The result is cached inside theLoadingCache
for one minute.Unfortunately
DatabaseMetaData#getTables
doesn't support case insensitive queries. In this case, it's still required to load all database tables to perform case insensitive lookups.The performance gain for huge sets of tables/schemas in database schemas can only be achieved if caching is turned off in Calcite (
SimpleCalciteSchema
is used instead ofCachingCalciteSchema
).I tried to keep the behavior of
CachingCalciteSchema
exactly the same. This behavior includes that all tables/schemas are loaded into memory.CachedLookup
is used to achieve this.