From ff47ca99834b1c6e380f8e5ad904002ae51fe9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Wed, 12 Jul 2023 20:13:09 +0200 Subject: [PATCH 1/2] Expand list of supported SQL range functions Closes #5745 --- edb/pgsql/resolver/range_functions.py | 424 +++++++++++++++++++++++++- 1 file changed, 421 insertions(+), 3 deletions(-) diff --git a/edb/pgsql/resolver/range_functions.py b/edb/pgsql/resolver/range_functions.py index 2ed2daa7c06..34339f61c19 100644 --- a/edb/pgsql/resolver/range_functions.py +++ b/edb/pgsql/resolver/range_functions.py @@ -27,7 +27,426 @@ 'jsonb_array_elements_text': ['value'], 'jsonb_each': ['key', 'value'], 'jsonb_each_text': ['key', 'value'], - 'pg_options_to_table': ['option_name', 'option_value'] + 'pg_available_extension_versions': [ + 'name', + 'version', + 'superuser', + 'trusted', + 'relocatable', + 'schema', + 'requires', + 'comment', + ], + 'pg_available_extensions': ['name', 'default_version', 'comment'], + 'pg_config': ['name', 'setting'], + 'pg_control_checkpoint': [ + 'checkpoint_lsn', + 'redo_lsn', + 'redo_wal_file', + 'timeline_id', + 'prev_timeline_id', + 'full_page_writes', + 'next_xid', + 'next_oid', + 'next_multixact_id', + 'next_multi_offset', + 'oldest_xid', + 'oldest_commit_ts_xid', + 'checkpoint_time', + 'newest_commit_ts_xid', + 'oldest_multi_dbid', + 'oldest_multi_xid', + 'oldest_active_xid', + 'oldest_xid_dbid', + ], + 'pg_control_init': [ + 'max_data_alignment', + 'database_block_size', + 'blocks_per_segment', + 'wal_block_size', + 'bytes_per_wal_segment', + 'max_identifier_length', + 'max_index_columns', + 'max_toast_chunk_size', + 'large_object_chunk_size', + 'float8_pass_by_value', + 'data_page_checksum_version', + ], + 'pg_control_recovery': [ + 'min_recovery_end_lsn', + 'min_recovery_end_timeline', + 'backup_start_lsn', + 'backup_end_lsn', + 'end_of_backup_record_required', + ], + 'pg_control_system': [ + 'pg_control_version', + 'catalog_version_no', + 'system_identifier', + 'pg_control_last_modified', + ], + 'pg_copy_logical_replication_slot': [ + 'slot_name', + 'slot_name', + 'lsn', + 'slot_name', + 'lsn', + 'lsn', + ], + 'pg_copy_physical_replication_slot': [ + 'slot_name', + 'lsn', + 'slot_name', + 'lsn', + ], + 'pg_create_logical_replication_slot': ['slot_name', 'lsn'], + 'pg_create_physical_replication_slot': ['slot_name', 'lsn'], + 'pg_cursor': [ + 'name', + 'statement', + 'is_holdable', + 'is_binary', + 'is_scrollable', + 'creation_time', + ], + 'pg_event_trigger_ddl_commands': [ + 'classid', + 'objid', + 'objsubid', + 'command_tag', + 'object_type', + 'schema_name', + 'object_identity', + 'in_extension', + 'command', + ], + 'pg_event_trigger_dropped_objects': [ + 'classid', + 'objid', + 'objsubid', + 'original', + 'normal', + 'is_temporary', + 'object_type', + 'schema_name', + 'object_name', + 'object_identity', + 'address_names', + 'address_args', + ], + 'pg_event_trigger_table_rewrite_oid': ['oid'], + 'pg_extension_update_paths': ['source', 'target', 'path'], + 'pg_get_backend_memory_contexts': [ + 'name', + 'ident', + 'parent', + 'level', + 'total_bytes', + 'total_nblocks', + 'free_bytes', + 'free_chunks', + 'used_bytes', + ], + 'pg_get_catalog_foreign_keys': [ + 'fktable', + 'fkcols', + 'pktable', + 'pkcols', + 'is_array', + 'is_opt', + ], + 'pg_get_keywords': ['word', 'catcode', 'barelabel', 'catdesc', 'baredesc'], + 'pg_get_multixact_members': ['xid', 'mode'], + 'pg_get_object_address': ['classid', 'objid', 'objsubid'], + 'pg_get_publication_tables': ['relid'], + 'pg_get_replication_slots': [ + 'slot_name', + 'plugin', + 'slot_type', + 'datoid', + 'temporary', + 'active', + 'active_pid', + 'xmin', + 'catalog_xmin', + 'restart_lsn', + 'confirmed_flush_lsn', + 'wal_status', + 'safe_wal_size', + 'two_phase', + ], + 'pg_get_shmem_allocations': ['name', 'off', 'size', 'allocated_size'], + 'pg_hba_file_rules': [ + 'line_number', + 'type', + 'database', + 'user_name', + 'address', + 'netmask', + 'auth_method', + 'options', + 'error', + ], + 'pg_identify_object': ['type', 'schema', 'name', 'identity'], + 'pg_identify_object_as_address': ['type', 'object_names', 'object_args'], + 'pg_last_committed_xact': ['xid', 'timestamp', 'roident'], + 'pg_lock_status': [ + 'locktype', + 'database', + 'relation', + 'page', + 'tuple', + 'virtualxid', + 'transactionid', + 'classid', + 'objid', + 'objsubid', + 'virtualtransaction', + 'pid', + 'fastpath', + 'waitstart', + 'granted', + 'mode', + ], + 'pg_logical_slot_get_binary_changes': ['lsn', 'xid', 'data'], + 'pg_logical_slot_get_changes': ['lsn', 'xid', 'data'], + 'pg_logical_slot_peek_binary_changes': ['lsn', 'xid', 'data'], + 'pg_logical_slot_peek_changes': ['lsn', 'xid', 'data'], + 'pg_ls_archive_statusdir': ['name', 'size', 'modification'], + 'pg_ls_logdir': ['name', 'size', 'modification'], + 'pg_ls_tmpdir': [ + 'name', + 'size', + 'name', + 'modification', + 'size', + 'modification', + ], + 'pg_ls_waldir': ['name', 'size', 'modification'], + 'pg_mcv_list_items': [ + 'index', + 'values', + 'nulls', + 'frequency', + 'base_frequency', + ], + 'pg_options_to_table': ['option_name', 'option_value'], + 'pg_partition_ancestors': ['relid'], + 'pg_partition_tree': ['relid', 'parentrelid', 'isleaf', 'level'], + 'pg_prepared_statement': [ + 'name', + 'statement', + 'prepare_time', + 'parameter_types', + 'from_sql', + 'generic_plans', + 'custom_plans', + ], + 'pg_prepared_xact': ['transaction', 'gid', 'prepared', 'ownerid', 'dbid'], + 'pg_replication_slot_advance': ['slot_name', 'end_lsn'], + 'pg_sequence_parameters': [ + 'start_value', + 'minimum_value', + 'maximum_value', + 'increment', + 'cycle_option', + 'cache_size', + 'data_type', + ], + 'pg_show_all_file_settings': [ + 'sourcefile', + 'sourceline', + 'seqno', + 'name', + 'setting', + 'applied', + 'error', + ], + 'pg_show_all_settings': [ + 'name', + 'setting', + 'unit', + 'category', + 'short_desc', + 'extra_desc', + 'context', + 'vartype', + 'source', + 'min_val', + 'max_val', + 'sourcefile', + 'sourceline', + 'pending_restart', + 'reset_val', + 'boot_val', + 'enumvals', + ], + 'pg_show_replication_origin_status': [ + 'local_id', + 'external_id', + 'remote_lsn', + 'local_lsn', + ], + 'pg_stat_file': [ + 'size', + 'size', + 'access', + 'modification', + 'access', + 'modification', + 'change', + 'change', + 'creation', + 'isdir', + 'creation', + 'isdir', + ], + 'pg_stat_get_activity': [ + 'datid', + 'pid', + 'usesysid', + 'application_name', + 'state', + 'query', + 'wait_event_type', + 'wait_event', + 'xact_start', + 'query_start', + 'ssl', + 'backend_start', + 'state_change', + 'client_addr', + 'client_hostname', + 'client_port', + 'backend_xid', + 'backend_xmin', + 'query_id', + 'leader_pid', + 'gss_enc', + 'gss_princ', + 'gss_auth', + 'ssl_issuer_dn', + 'ssl_client_serial', + 'ssl_client_dn', + 'sslbits', + 'sslcipher', + 'sslversion', + 'backend_type', + ], + 'pg_stat_get_archiver': [ + 'archived_count', + 'last_archived_wal', + 'last_archived_time', + 'failed_count', + 'last_failed_wal', + 'last_failed_time', + 'stats_reset', + ], + 'pg_stat_get_progress_info': [ + 'pid', + 'datid', + 'relid', + 'param1', + 'param2', + 'param3', + 'param4', + 'param5', + 'param6', + 'param7', + 'param20', + 'param18', + 'param17', + 'param16', + 'param15', + 'param14', + 'param13', + 'param12', + 'param11', + 'param10', + 'param9', + 'param8', + 'param19', + ], + 'pg_stat_get_replication_slot': [ + 'slot_name', + 'spill_txns', + 'spill_count', + 'spill_bytes', + 'stream_txns', + 'stream_count', + 'stream_bytes', + 'total_txns', + 'total_bytes', + 'stats_reset', + ], + 'pg_stat_get_slru': [ + 'name', + 'blks_zeroed', + 'blks_hit', + 'blks_read', + 'blks_written', + 'blks_exists', + 'flushes', + 'truncates', + 'stats_reset', + ], + 'pg_stat_get_subscription': [ + 'subid', + 'relid', + 'pid', + 'received_lsn', + 'last_msg_send_time', + 'last_msg_receipt_time', + 'latest_end_lsn', + 'latest_end_time', + ], + 'pg_stat_get_wal': [ + 'wal_records', + 'wal_fpi', + 'wal_bytes', + 'wal_buffers_full', + 'wal_write', + 'wal_sync', + 'wal_write_time', + 'wal_sync_time', + 'stats_reset', + ], + 'pg_stat_get_wal_receiver': [ + 'pid', + 'status', + 'receive_start_lsn', + 'receive_start_tli', + 'written_lsn', + 'flushed_lsn', + 'received_tli', + 'last_msg_send_time', + 'last_msg_receipt_time', + 'latest_end_lsn', + 'latest_end_time', + 'slot_name', + 'sender_host', + 'sender_port', + 'conninfo', + ], + 'pg_stat_get_wal_senders': [ + 'pid', + 'state', + 'sent_lsn', + 'write_lsn', + 'flush_lsn', + 'replay_lsn', + 'write_lag', + 'flush_lag', + 'replay_lag', + 'sync_priority', + 'sync_state', + 'reply_time', + ], + 'pg_stop_backup': ['lsn', 'labelfile', 'spcmapfile'], + 'pg_timezone_abbrevs': ['abbrev', 'utc_offset', 'is_ds'], + 'pg_timezone_names': ['name', 'abbrev', 'utc_offset', 'is_dst'], + 'pg_walfile_name_offset': ['file_name', 'file_offset'], + 'pg_xact_commit_timestamp_origin': ['timestamp', 'roident'], } # retrieved with @@ -36,8 +455,7 @@ procedures AS ( SELECT * FROM pg_proc - WHERE proname NOT ILIKE 'pg\_%' - AND proname NOT ILIKE 'ts\_%' + WHERE proname NOT ILIKE 'ts\_%' AND proname NOT ILIKE '\_%' AND proname != 'unnest' AND proname != 'aclexplode' From 9d2025bc8a0b559ca2714dcadde6a7f87a5bbb48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Wed, 12 Jul 2023 21:29:12 +0200 Subject: [PATCH 2/2] Fix psql \dt Closes #5676 Adds support for `pg_table_is_visible`. We might want to support other similar functions: https://www.postgresql.org/docs/9.5/functions-info.html#FUNCTIONS-INFO-SCHEMA-TABLE --- edb/pgsql/metaschema.py | 18 ++++++++++++++++++ edb/pgsql/resolver/static.py | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/edb/pgsql/metaschema.py b/edb/pgsql/metaschema.py index e1f30cf1203..6c39795c95a 100644 --- a/edb/pgsql/metaschema.py +++ b/edb/pgsql/metaschema.py @@ -6424,6 +6424,24 @@ def construct_pg_view(table_name: str, columns: List[str]) -> dbops.View: END """ ), + dbops.Function( + name=('edgedbsql', 'pg_table_is_visible'), + args=[ + ('id', ('oid',)), + ('search_path', ('text[]',)), + ], + returns=('bool',), + volatility='stable', + text=r''' + SELECT pc.relnamespace IN ( + SELECT oid + FROM edgedbsql.pg_namespace pn + WHERE pn.nspname IN (select * from unnest(search_path)) + ) + FROM edgedbsql.pg_class pc + WHERE id = pc.oid + ''' + ) ] return ( diff --git a/edb/pgsql/resolver/static.py b/edb/pgsql/resolver/static.py index 596c32a0238..05e5efd3af0 100644 --- a/edb/pgsql/resolver/static.py +++ b/edb/pgsql/resolver/static.py @@ -246,6 +246,22 @@ def eval_FuncCall( return pgast.FuncCall(name=('pg_catalog', fn_name), args=fn_args) + if fn_name == 'pg_table_is_visible': + arg_0 = dispatch.resolve(expr.args[0], ctx=ctx) + + # our *_is_visible functions need search_path, passed in as an array + arg_1 = pgast.ArrayExpr( + elements=[ + pgast.StringConstant(val=v) + for v in ctx.options.search_path + ] + ) + + return pgast.FuncCall( + name=('edgedbsql', fn_name), + args=[arg_0, arg_1] + ) + return None