Skip to content

Conversation

mkaruza
Copy link
Contributor

@mkaruza mkaruza commented Jan 20, 2025

No description provided.

@mkaruza
Copy link
Contributor Author

mkaruza commented Jan 20, 2025

Preparation for DuckDB 1.2 release, should be merged once version is officially released with extensions

PostgresScanTableFunction::ToString(duckdb::TableFunctionToStringInput &input) {
auto &bind_data = input.bind_data->Cast<PostgresScanFunctionData>();
duckdb::InsertionOrderPreservingMap<duckdb::string> result;
result["Table"] = GetRelationName(bind_data.rel);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe interesting to note that it is a PG table?

Suggested change
result["Table"] = GetRelationName(bind_data.rel);
result["Table"] = GetRelationName(bind_data.rel) + " (PG)";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Explain already show it is POSTGRES_SCAN node. We can add it if needed.

Copy link
Collaborator

@JelteF JelteF Jan 27, 2025

Choose a reason for hiding this comment

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

It doesn't show that for explain analyze for some reason I think.

Copy link
Collaborator

Choose a reason for hiding this comment

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

}
case duckdb::TableFilterType::STRUCT_EXTRACT:
case duckdb::TableFilterType::DYNAMIC_FILTER:
scan_query << "1 = 1";
Copy link
Collaborator

@JelteF JelteF Jan 21, 2025

Choose a reason for hiding this comment

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

This seems like a bit of a hack. Do we really need this? If so, can you add a comment explaining why?

Also, is this actually correct? Because now we don't actually filter anything for these filter types inside postgres, but duckdb will not filter on that side either. I feel like we probably need some tests that show that we return correct result when using these kind of things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated construction of pushdown filters. Looking at duckdb code STRUCT_EXTRACT is only created if struct_extract is used in query, while DYNAMIC_FILTER is constructed when there is topN node (LIMIT). Both of these should not matter to filtering.

}
/* DYNAMIC_FILTER is push down filter from topN execution */
case duckdb::TableFilterType::DYNAMIC_FILTER:
return 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we return 0 here instead of throwing an error? Do we have a query that triggers this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DYNAMIC_QUERY happens when there is LIMIT in query so we'll see this filter pushed down to scan, but we can't do anything about it except to skip it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Alright, I looked a bit closer at the code and understand much better what all these things are: I think a somewhat cleaner/future-proof way of handling this is by remembering if we're in an optional filter or not (probably by passing it as a third argument to the recursive function). Then for all these filters that we don't support, we do nothing if it's inside an optional filter, or throw an error if it's not inside an optional filter.

}
/* DYNAMIC_FILTER is push down filter from topN execution */
case duckdb::TableFilterType::DYNAMIC_FILTER:
return 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now it should be possible to remove this line right?

Suggested change
return 0;

@JelteF JelteF added this to the 0.3.0 milestone Jan 28, 2025

int
PostgresScanGlobalState::ExtractQueryFilters(duckdb::TableFilter *filter, const char *column_name,
duckdb::string &query_filters, bool is_optional_filter_parent) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: "parent" seems like the wrong naming imo. Maybe one of these names instead:

Suggested change
duckdb::string &query_filters, bool is_optional_filter_parent) {
duckdb::string &query_filters, bool is_optional_filter_child) {
Suggested change
duckdb::string &query_filters, bool is_optional_filter_parent) {
duckdb::string &query_filters, bool is_inside_optional_filter) {

@Y-- Y-- merged commit de3735a into main Feb 6, 2025
5 checks passed
@Y-- Y-- deleted the duckdb-1.2 branch February 6, 2025 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants