Skip to content

Commit 3614006

Browse files
committed
Summary: Correctly handle schema qualfied filter columns
This was assuming list_nth_cell returned a node pointer, but omitted the required lfirst to turn the list cell into a pointer. Instead use the convenience lsecond_node function.
1 parent 00c20a7 commit 3614006

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/pg_query_summary.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ pg_query_summary_walk_impl(Node *node, WalkState * state)
537537
else if (num_fields == 3)
538538
{
539539
schema_name = linitial(ref->fields);
540-
table_name = castNode(String, list_nth_cell(ref->fields, 1));
540+
table_name = lsecond_node(String, ref->fields);
541541
}
542542

543543
FilterColumn *fc = palloc(sizeof(FilterColumn));

test/summary_tests.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,3 +1067,9 @@ void it_handles_all_tables_in_schema(TestState* test_state) {
10671067
Summary result = summary("GRANT SELECT ON ALL TABLES IN SCHEMA public TO myrole", 0, -1);
10681068
TEST_ASSERT_LIST_LENGTH(result.filter_columns, 0);
10691069
}
1070+
1071+
void it_handles_schema_qualified_columns(TestState* test_state) {
1072+
Summary result = summary("SELECT * FROM b.c WHERE a.b.c = 1", 0, -1);
1073+
TEST_ASSERT_LIST_LENGTH(result.filter_columns, 1);
1074+
TEST_SUMMARY_ASSERT_FILTER_COLUMN(result.filter_columns, "a", "b", "c");
1075+
}

test/summary_tests_list.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,4 @@
9191
&it_ignores_target_list_columns,
9292
&it_ignores_order_by_columns,
9393
&it_handles_all_tables_in_schema,
94+
&it_handles_schema_qualified_columns,

0 commit comments

Comments
 (0)