Major performance improvements #187
Merged
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.
This change addresses a few major performance issues
connectinterface should be lightweight and any processing should be done lazily. This change addresses that by removing thepopulatemethods found in each driver and instead overloadingtables()in each schema to load only when tables are needed for a given driver.tables()) has two relevant methodsget(String name)to retrieve a single table by name, andgetNames(LikePattern pattern)to retrieve all table names that match a regex. In practice, Calcite calls these functions many times:LazyTableLookupto cache repeated callsgetNameswith the regex matching a single name to validate that a table exists. Added a micro-optimization in this case to only actually load all tables when a real regex pattern is used.getNamesis called often after repeatedgetcalls but I don't see this access pattern in practice.CachingCalciteSchemawill be used, if notSimpleCalciteSchemawill be used.CachingCalciteSchemaattempts to cache table and function retrieval, however, in practice this clashes with the above caching we have at the driver schema level. Additionally, the wayCachingCalciteSchemacaches is by using aSnapshotLookupwhich will eagerly load all tables and store a snapshot of the whole schema + all tables at instantiation time. It also bizarrely only cachesget(String name)calls, notgetNames(LikePattern pattern)calls, which leads to a lot of redundancy. This change implementsCalciteDriveron top ofDriverwhich simply exposes the ability to enable caching or not. Caching at the driver level is by default disabled now, relying instead on caching at the table level (implemented byLazyTableLookup) instead.Added testing for
LazyTableLookup, validated many existing code paths including !tables, !describe, creating views, cli, etc.Did some performance analysis internally, planning a pipeline in a test environment (low number of databases & tables) was taking upwards of ~35s for a simple SELECT query. With these changes the same query is taking ~5s. I expect a much bigger difference when more drivers or drivers with many more tables are loaded.