@@ -678,18 +678,22 @@ vacuum_one_database(ConnParams *cparams,
678
678
/* Used to match the tables or schemas listed by the user */
679
679
if (objects_listed )
680
680
{
681
- appendPQExpBufferStr (& catalog_query , " JOIN listed_objects"
682
- " ON listed_objects.object_oid " );
683
-
684
- if (objfilter & OBJFILTER_SCHEMA_EXCLUDE )
685
- appendPQExpBufferStr (& catalog_query , "OPERATOR(pg_catalog.!=) " );
686
- else
687
- appendPQExpBufferStr (& catalog_query , "OPERATOR(pg_catalog.=) " );
681
+ appendPQExpBufferStr (& catalog_query , " LEFT JOIN listed_objects"
682
+ " ON listed_objects.object_oid"
683
+ " OPERATOR(pg_catalog.=) " );
688
684
689
685
if (objfilter & OBJFILTER_TABLE )
690
686
appendPQExpBufferStr (& catalog_query , "c.oid\n" );
691
687
else
692
688
appendPQExpBufferStr (& catalog_query , "ns.oid\n" );
689
+
690
+ if (objfilter & OBJFILTER_SCHEMA_EXCLUDE )
691
+ appendPQExpBuffer (& catalog_query ,
692
+ " WHERE listed_objects.object_oid IS NULL\n" );
693
+ else
694
+ appendPQExpBuffer (& catalog_query ,
695
+ " WHERE listed_objects.object_oid IS NOT NULL\n" );
696
+ has_where = true;
693
697
}
694
698
695
699
/*
@@ -700,9 +704,11 @@ vacuum_one_database(ConnParams *cparams,
700
704
*/
701
705
if ((objfilter & OBJFILTER_TABLE ) == 0 )
702
706
{
703
- appendPQExpBufferStr (& catalog_query , " WHERE c.relkind OPERATOR(pg_catalog.=) ANY (array["
704
- CppAsString2 (RELKIND_RELATION ) ", "
705
- CppAsString2 (RELKIND_MATVIEW ) "])\n" );
707
+ appendPQExpBuffer (& catalog_query ,
708
+ " %s c.relkind OPERATOR(pg_catalog.=) ANY (array["
709
+ CppAsString2 (RELKIND_RELATION ) ", "
710
+ CppAsString2 (RELKIND_MATVIEW ) "])\n" ,
711
+ has_where ? "AND" : "WHERE" );
706
712
has_where = true;
707
713
}
708
714
0 commit comments