From a2c251cfb91178989ee5e2275c49214151ee9671 Mon Sep 17 00:00:00 2001 From: Kundan Sable Date: Wed, 22 Jul 2026 14:40:00 +0530 Subject: [PATCH] feat: add preference for default View Data row limit The plain "View Data" shortcut always performs a SELECT * with no LIMIT, which is effectively unusable on large tables since it always tries to fetch every row. "First/Last 100 Rows" already avoid this by hardcoding limit=100, but there was no way to make the default, unqualified "View Data" action bounded. Add a new preference, view_data_default_row_limit (integer, default 0 = unlimited, preserving current behavior), and apply it in GridCommand.__init__ only for the VIEW_ALL_ROWS command type. The existing objectquery.sql template already renders a LIMIT clause only when limit > 0, so a positive preference value takes effect with no template changes. First/Last 100 Rows are unaffected. Fixes #10104 --- web/pgadmin/tools/sqleditor/command.py | 8 ++++++++ .../sqleditor/utils/query_tool_preferences.py | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/web/pgadmin/tools/sqleditor/command.py b/web/pgadmin/tools/sqleditor/command.py index 9675022853d..fb7a9d5f87b 100644 --- a/web/pgadmin/tools/sqleditor/command.py +++ b/web/pgadmin/tools/sqleditor/command.py @@ -363,6 +363,14 @@ def __init__(self, **kwargs): if self.cmd_type in (VIEW_FIRST_100_ROWS, VIEW_LAST_100_ROWS): self.limit = 100 + elif self.cmd_type == VIEW_ALL_ROWS: + # Apply the user-configurable default row limit (if any) for the + # "All Rows" option. A value of 0 (the default) means no limit, + # preserving the existing behaviour of fetching all rows. + default_row_limit = Preferences.module('sqleditor').preference( + 'view_data_default_row_limit').get() + if default_row_limit and default_row_limit > 0: + self.limit = default_row_limit self.thread_native_id = None self.server_cursor = kwargs['server_cursor'] if\ diff --git a/web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py b/web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py index a18edb13843..bf13167fc22 100644 --- a/web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py +++ b/web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py @@ -120,6 +120,21 @@ def register_query_tool_preferences(self): "First/Last 100 Rows options, data is always sorted.") ) + self.view_data_default_row_limit = self.preference.register( + 'Options', 'view_data_default_row_limit', + gettext("Default row limit for View Data"), 'integer', 0, + min_val=0, + category_label=PREF_LABEL_OPTIONS, + help_str=gettext( + "Specify the maximum number of rows to fetch when using the " + "View/Edit Data - All Rows option. This appends a LIMIT clause " + "to the generated query, which can significantly improve " + "performance on very large tables. Set to 0 (the default) to " + "fetch all rows with no limit (the existing behavior). This " + "does not affect the First/Last 100 Rows options." + ) + ) + self.show_prompt_save_data_changes = self.preference.register( 'Options', 'prompt_save_data_changes', gettext("Prompt to save unsaved data changes?"), 'boolean', True,