25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(grid): budget large-value previews by segment and show executed SQL
zipg237064f9e3c4
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vueindex bbb76f1213..080b898f2a 100644--- a/apps/desktop/src/components/grid/DataGrid.vue+++ b/apps/desktop/src/components/grid/DataGrid.vue@@ -217,6 +217,7 @@ import {canGoNextDataGridPage,dataGridLoadAllSegment,dataGridTotalRowCountLabelKey,+ dataGridUserFacingPage,dataGridTruncationHintKey,ELASTICSEARCH_PAGE_JUMP_WARNING_REQUESTS,elasticsearchCursorPageJumpRequestCount,@@ -501,6 +502,13 @@ interface DataGridProps {autoShowTableInfo?: boolean;pageOffset?: number;pageLimit?: number;+ /**+ * Pagination of the segment that produced the currently displayed rows. It+ * differs from `pageOffset`/`pageLimit` once a result was extended by+ * "load all" or infinite scroll, because those stay on the logical first page.+ */+ executedPageOffset?: number;+ executedPageLimit?: number;countSql?: string;totalRowCount?: number;totalRowCountIsExact?: boolean;@@ -7858,6 +7866,14 @@ async function syncUserFacingSql() {try {const config = props.connectionId ? connectionStore.getConfig(props.connectionId) : undefined;+ const footerPage = dataGridUserFacingPage({+ executedPageLimit: props.executedPageLimit,+ executedPageOffset: props.executedPageOffset,+ pageLimit: props.pageLimit,+ pageOffset: props.pageOffset,+ fallbackLimit: pageSize.value,+ fallbackOffset: Math.max(0, currentPage.value - 1) * pageSize.value,+ });const sql = await buildTableSelectSql({databaseType: resolvedDatabaseType.value,driverProfile: config?.driver_profile,@@ -7872,8 +7888,8 @@ async function syncUserFacingSql() {injectDefaultTimeSeriesWhere: true,whereInput: currentWhereInput(),orderBy: currentOrderBy(),- limit: props.pageLimit ?? pageSize.value,- offset: props.pageOffset ?? Math.max(0, currentPage.value - 1) * pageSize.value,+ limit: footerPage.limit,+ offset: footerPage.offset,});if (generation === userFacingSqlGeneration) userFacingSql.value = sqlWithDisplayDatabaseName(sql);} catch {@@ -7882,7 +7898,7 @@ async function syncUserFacingSql() {}watch(- () => [props.sql, props.context, props.tableMeta, props.pageLimit, props.pageOffset, currentWhereInput(), currentOrderBy(), settingsStore.editorSettings.generateSqlIncludeDatabaseName],+ () => [props.sql, props.context, props.tableMeta, props.pageLimit, props.pageOffset, props.executedPageLimit, props.executedPageOffset, currentWhereInput(), currentOrderBy(), settingsStore.editorSettings.generateSqlIncludeDatabaseName],() => void syncUserFacingSql(),{ immediate: true },);diff --git a/apps/desktop/src/components/layout/ContentArea.vue b/apps/desktop/src/components/layout/ContentArea.vueindex e2f4e5082f..77e7c36071 100644--- a/apps/desktop/src/components/layout/ContentArea.vue+++ b/apps/desktop/src/components/layout/ContentArea.vue@@ -2352,6 +2352,8 @@ defineExpose({:table-info-tab="activeTab.tableInfoTab":page-offset="activeTab.resultPageOffset":page-limit="activeTab.resultPageLimit"+ :executed-page-offset="activeTab.resultExecutedPageOffset"+ :executed-page-limit="activeTab.resultExecutedPageLimit":count-sql="activeTab.resultCountSql":count-total-rows="activeTab.resultCountSql ? () => queryStore.countTabResultRows(activeTab.id) : undefined":total-row-count="activeTab.resultTotalRowCount"@@ -2802,6 +2804,8 @@ defineExpose({:auto-show-table-info="settingsStore.editorSettings.tableInfoDrawerPinned":page-offset="activeTab.resultPageOffset":page-limit="activeTab.resultPageLimit"+ :executed-page-offset="activeTab.resultExecutedPageOffset"+ :executed-page-limit="activeTab.resultExecutedPageLimit":total-row-count="activeTab.resultTotalRowCount":total-row-count-is-exact="activeTab.resultTotalRowCount !== undefined || activeTab.result.total_is_exact !== false":total-row-count-loading="activeTab.resultTotalRowCountLoading"diff --git a/apps/desktop/src/composables/__tests__/useDataGridActions.spec.ts b/apps/desktop/src/composables/__tests__/useDataGridActions.spec.tsindex 9eb6a5e911..067c399aa9 100644--- a/apps/desktop/src/composables/__tests__/useDataGridActions.spec.ts+++ b/apps/desktop/src/composables/__tests__/useDataGridActions.spec.ts@@ -589,6 +589,35 @@ describe("useDataGridActions", () => {expect(mocks.executeTabSql).toHaveBeenCalledWith("tab-1", "SELECT * FROM public.users LIMIT 100 OFFSET 100", expect.objectContaining({ appendResult: { maxRows: 10_000 } }));});+ it("budgets a load-all large-value preview against the rows the table still has", async () => {+ const columns = [+ { name: "id", data_type: "bigint", is_nullable: false, column_default: null, is_primary_key: true, extra: null },+ ...Array.from({ length: 10 }, (_, index) => ({ name: `payload_${index}`, data_type: "varchar(64)", is_nullable: true, column_default: null, is_primary_key: false, extra: null })),+ ];+ const tab = tableDataTab({+ resultTotalRowCount: 506,+ resultPageLimit: 100,+ resultPageOffset: 0,+ result: {+ columns: ["id", "payload_0"],+ rows: Array.from({ length: 100 }, (_, index) => [index + 1, "19999386"]),+ affected_rows: 0,+ execution_time_ms: 1,+ },+ tableMeta: { schema: "ads", tableName: "ads_platform_order_receiver", tableType: "TABLE", columns, primaryKeys: ["id"] },+ });+ mocks.buildTableSelectSql.mockResolvedValueOnce('SELECT * FROM "ads"."ads_platform_order_receiver" LIMIT 99900 OFFSET 100;');+ mocks.tabs.push(tab);+ const actions = useDataGridActions(computed(() => tab));++ // "Load all" asks for the whole remaining table; the preview budget has to be+ // spread over the 406 rows that can still arrive, not over the 99_900 asked for.+ await actions.onPaginate(tab.id, 100, 99_900, "", undefined, true);++ expect(mocks.buildTableSelectSql).toHaveBeenCalledWith(expect.objectContaining({ limit: 99_900, offset: 100, largeValuePreviewSize: 1033 }));+ expect(mocks.executeTabSql).toHaveBeenCalledWith("tab-1", expect.any(String), expect.objectContaining({ pagination: { offset: 100, limit: 99_900, sessionId: undefined, clientSessionId: undefined } }));+ });+it("continues the matching Cassandra table cursor and client session", async () => {mocks.infiniteScroll = false;mocks.getConfig.mockReturnValue({ id: "cassandra-1", db_type: "cassandra" });diff --git a/apps/desktop/src/composables/useDataGridActions.ts b/apps/desktop/src/composables/useDataGridActions.tsindex 0c6cd2ce3b..31254b79f9 100644--- a/apps/desktop/src/composables/useDataGridActions.ts+++ b/apps/desktop/src/composables/useDataGridActions.ts@@ -6,7 +6,7 @@ import { useQueryStore } from "@/stores/queryStore";import { useSettingsStore } from "@/stores/settingsStore";import { buildTableSelectSql, quoteTableDataIdentifier } from "@/lib/table/tableSelectSql";import { tableOpenPageLimit } from "@/lib/table/tableOpenPageLimit";-import { tableDataLargeValuePreviewOptions } from "@/lib/dataGrid/dataGridLargeValues";+import { tableDataLargeValuePreviewOptions, tableDataPreviewRowBudget } from "@/lib/dataGrid/dataGridLargeValues";import { elasticsearchCursorPageJumpRequestCount } from "@/lib/dataGrid/dataGridPagination";import { editablePrimaryKeys, shouldIncludeSyntheticRowId } from "@/lib/table/tableEditing";import { tableMetaForDataTab } from "@/lib/table/tableDataTabMeta";@@ -108,7 +108,8 @@ export function useDataGridActions(activeTab: ComputedRef<QueryTab | undefined>)return typeof limit === "number" && limit > 0 ? { limit, offset: 0 } : undefined;}- function buildTableSql(tab: QueryTab, options: { orderBy?: string; limit?: number; offset?: number; whereInput?: string } = {}): Promise<string> {+ function buildTableSql(tab: QueryTab, options: { orderBy?: string; limit?: number; offset?: number; whereInput?: string; previewPageSize?: number } = {}): Promise<string> {+ const { previewPageSize, ...sqlOptions } = options;const config = connectionStore.getConfig(tab.connectionId);const effectiveDbType = effectiveDatabaseTypeForConnection(config);const tableMeta = tableMetaForDataTab(tab);@@ -118,7 +119,9 @@ export function useDataGridActions(activeTab: ComputedRef<QueryTab | undefined>)// 结果(可能是失败结果的 ["Error"]),进入 SQL 会生成非法投影;// 真实列缺失时省略 columns 让 builder 生成 SELECT *const realColumns = tab.tableMeta?.columns.length ? tab.tableMeta.columns : undefined;- const limit = options.limit ?? tableDataPageLimit(tab);+ const limit = sqlOptions.limit ?? tableDataPageLimit(tab);+ // The preview budget is a per-fetch byte budget, so it has to be spread over+ // the rows this fetch returns rather than over the rows it asks for.return buildTableSelectSql({databaseType: effectiveDbType,driverProfile: config?.driver_profile,@@ -131,12 +134,12 @@ export function useDataGridActions(activeTab: ComputedRef<QueryTab | undefined>)catalog: tableMeta?.catalog,columns: realColumns?.map((column) => column.name),primaryKeys,- ...tableDataLargeValuePreviewOptions(effectiveDbType, realColumns ?? [], primaryKeys, limit),+ ...tableDataLargeValuePreviewOptions(effectiveDbType, realColumns ?? [], primaryKeys, previewPageSize ?? limit),includeDatabaseName: settingsStore.editorSettings.generateSqlIncludeDatabaseName,includeRowId: useRowId,limit,injectDefaultTimeSeriesWhere: true,- ...options,+ ...sqlOptions,});}@@ -599,7 +602,18 @@ export function useDataGridActions(activeTab: ComputedRef<QueryTab | undefined>)if (!tableMetaForDataTab(tab)) return;tab.whereInput = whereInput ?? "";- const sql = await buildTableSql(tab, { limit, offset, whereInput, orderBy: orderBy ?? tab.orderByInput });+ const sql = await buildTableSql(tab, {+ limit,+ offset,+ whereInput,+ orderBy: orderBy ?? tab.orderByInput,+ previewPageSize: tableDataPreviewRowBudget({+ limit,+ offset,+ expectedTotalRows: tab.resultTotalRowCount,+ loadedRowCount: tab.result?.rows.length ?? 0,+ }),+ });queryStore.updateSql(tab.id, sql);const expectedNextOffset = appendResult ? tab.result?.rows.length : (tab.resultPageOffset ?? 0) + (tab.resultPageLimit ?? limit);const continuesResultSession = offset === expectedNextOffset && limit === tab.resultPageLimit;diff --git a/apps/desktop/src/lib/__tests__/dataGrid/dataGridLargeValues.spec.ts b/apps/desktop/src/lib/__tests__/dataGrid/dataGridLargeValues.spec.tsindex 11ddac4336..051aaa6de4 100644--- a/apps/desktop/src/lib/__tests__/dataGrid/dataGridLargeValues.spec.ts+++ b/apps/desktop/src/lib/__tests__/dataGrid/dataGridLargeValues.spec.ts@@ -10,6 +10,7 @@ import {TABLE_DATA_CELL_PREVIEW_SIZE,TABLE_DATA_PREVIEW_CONTENT_MAX_BYTES,tableDataLargeValuePreviewOptions,+ tableDataPreviewRowBudget,tableDataVisiblePreviewContentBytes,tableDataVisiblePreviewRowRange,} from "@/lib/dataGrid/dataGridLargeValues";@@ -79,6 +80,35 @@ describe("data grid large-value metadata", () => {}});+ it("spreads the load-all byte budget over the rows the segment will really return", () => {+ // Issue #10661: a 506-row table asked for a 99_900-row "load all" segment.+ // Budgeting over the request instead of the remaining rows shrank every cell+ // to four characters ("1999..."), so off-screen rows arrived already garbled.+ const rowBudget = tableDataPreviewRowBudget({ limit: 99_900, offset: 100, expectedTotalRows: 506, loadedRowCount: 100 });+ expect(rowBudget).toBe(406);++ const columns = [column("id", "bigint", true), ...Array.from({ length: 10 }, (_, index) => column(`payload_${index}`, "varchar(64)"))];+ const loadAll = tableDataLargeValuePreviewOptions("postgres", columns, ["id"], rowBudget);+ const requested = tableDataLargeValuePreviewOptions("postgres", columns, ["id"], 99_900);+ expect(loadAll).toMatchObject({ largeValuePreviewSize: 1033 });+ expect(requested).toMatchObject({ largeValuePreviewSize: 4 });+ });++ it("keeps the requested limit when the real row count is unknown or unusable", () => {+ // A normal page never shrinks the budget.+ expect(tableDataPreviewRowBudget({ limit: 100, offset: 0, expectedTotalRows: 506, loadedRowCount: 100 })).toBe(100);+ expect(tableDataPreviewRowBudget({ limit: 100, offset: 400, expectedTotalRows: 506, loadedRowCount: 400 })).toBe(100);+ // Last short page may use the rows that can still arrive.+ expect(tableDataPreviewRowBudget({ limit: 100, offset: 450, expectedTotalRows: 506, loadedRowCount: 450 })).toBe(56);+ // No known total: keep the previous behaviour.+ expect(tableDataPreviewRowBudget({ limit: 99_900, offset: 100, expectedTotalRows: undefined, loadedRowCount: 100 })).toBe(99_900);+ // A total below the rows already on screen (e.g. an affected_rows hint of 1)+ // must not balloon the preview budget.+ expect(tableDataPreviewRowBudget({ limit: 99_900, offset: 100, expectedTotalRows: 1, loadedRowCount: 100 })).toBe(99_900);+ expect(tableDataPreviewRowBudget({ limit: 99_900, offset: 100, expectedTotalRows: Number.NaN, loadedRowCount: 100 })).toBe(99_900);+ expect(tableDataPreviewRowBudget({ limit: 99_900, offset: 506, expectedTotalRows: 506, loadedRowCount: 506 })).toBe(99_900);+ });+it("selects the visible rows plus a bounded viewport buffer", () => {expect(tableDataVisiblePreviewRowRange(26 * 50, 26 * 20, 26, 10_000)).toEqual({ start: 30, end: 90 });expect(tableDataVisiblePreviewRowRange(0, 26 * 20, 26, 10_000)).toEqual({ start: 0, end: 60 });diff --git a/apps/desktop/src/lib/dataGrid/dataGridLargeValues.ts b/apps/desktop/src/lib/dataGrid/dataGridLargeValues.tsindex 4d54b713ca..ff8e376e78 100644--- a/apps/desktop/src/lib/dataGrid/dataGridLargeValues.ts+++ b/apps/desktop/src/lib/dataGrid/dataGridLargeValues.ts@@ -178,6 +178,23 @@ export function canUseTableDataLargeValuePreview(databaseType: DatabaseType | unreturn (databaseType === "mysql" || databaseType === "postgres") && columns.length > 0 && primaryKeys.length > 0 && !columns.some((column) => column.name.toLocaleUpperCase().startsWith(TABLE_DATA_LARGE_VALUE_MARKER_PREFIX));}+/**+ * Rows one fetch is expected to return, used to spread the large-value byte+ * budget over the rows that will actually arrive. "Load all" and infinite scroll+ * ask for the whole remaining table in one segment, so dividing the budget by+ * that request shrinks every preview to a couple of characters even when the+ * table only holds a few hundred rows.+ */+export function tableDataPreviewRowBudget(options: { limit: number; offset: number; expectedTotalRows: number | undefined; loadedRowCount: number }): number {+ const { limit, offset, expectedTotalRows, loadedRowCount } = options;+ // A total below the rows already on screen is not a usable row estimate (e.g.+ // an `affected_rows` hint of 1), so keep the requested limit.+ if (typeof expectedTotalRows !== "number" || !Number.isFinite(expectedTotalRows) || expectedTotalRows < loadedRowCount) return limit;+ const remainingRows = expectedTotalRows - offset;+ if (remainingRows <= 0 || remainingRows >= limit) return limit;+ return remainingRows;+}+export function tableDataLargeValuePreviewOptions(databaseType: DatabaseType | undefined, columns: readonly ColumnInfo[], primaryKeys: readonly string[], pageSize?: number): { columnTypes: string[]; largeValuePreviewSize: number } | Record<string, never> {if (!canUseTableDataLargeValuePreview(databaseType, columns, primaryKeys)) return {};const keyColumns = new Set(primaryKeys.map((column) => column.toLocaleLowerCase()));diff --git a/apps/desktop/src/lib/dataGrid/dataGridPagination.ts b/apps/desktop/src/lib/dataGrid/dataGridPagination.tsindex 846dae9449..aba60d23c4 100644--- a/apps/desktop/src/lib/dataGrid/dataGridPagination.ts+++ b/apps/desktop/src/lib/dataGrid/dataGridPagination.ts@@ -115,6 +115,19 @@ export function canFetchNextDataGridSegment(options: CanFetchNextDataGridSegmentreturn options.loadedRowCount >= Math.max(1, options.pageSize);}+/**+ * Page that the SQL shown under the grid describes. `executedPage*` is the+ * segment that actually ran — it can be the whole remaining table after+ * "load all" — while `page*` intentionally stays on the logical first page of+ * the displayed result, so it cannot describe an extended result on its own.+ */+export function dataGridUserFacingPage(options: { executedPageLimit?: number; executedPageOffset?: number; pageLimit?: number; pageOffset?: number; fallbackLimit: number; fallbackOffset: number }): { limit: number; offset: number } {+ return {+ limit: options.executedPageLimit ?? options.pageLimit ?? options.fallbackLimit,+ offset: options.executedPageOffset ?? options.pageOffset ?? options.fallbackOffset,+ };+}+export function dataGridLoadAllSegment(loadedRowCount: number, maxRows: number, canFetchMore: boolean): DataGridLoadAllSegment | null {const offset = Number.isFinite(loadedRowCount) ? Math.max(0, Math.trunc(loadedRowCount)) : 0;const boundedMaxRows = Number.isFinite(maxRows) ? Math.max(0, Math.trunc(maxRows)) : 0;diff --git a/apps/desktop/src/lib/tabs/tabResultCache.ts b/apps/desktop/src/lib/tabs/tabResultCache.tsindex ddc2f98b73..90b7b0bd67 100644--- a/apps/desktop/src/lib/tabs/tabResultCache.ts+++ b/apps/desktop/src/lib/tabs/tabResultCache.ts@@ -49,6 +49,8 @@ export interface TabResultSnapshot {resultPageSql?: string;resultPageLimit?: number;resultPageOffset?: number;+ resultExecutedPageLimit?: number;+ resultExecutedPageOffset?: number;resultCountSql?: string;resultTotalRowCount?: number;cachedAt: number;@@ -811,6 +813,8 @@ export function buildTabResultSnapshot(tab: QueryTab): TabResultSnapshot | undefresultPageSql: tab.resultPageSql,resultPageLimit: tab.resultPageLimit,resultPageOffset: tab.resultPageOffset,+ resultExecutedPageLimit: tab.resultExecutedPageLimit,+ resultExecutedPageOffset: tab.resultExecutedPageOffset,resultCountSql: tab.resultCountSql,resultTotalRowCount: tab.resultTotalRowCount,cachedAt: Date.now(),diff --git a/apps/desktop/src/stores/queryStore.ts b/apps/desktop/src/stores/queryStore.tsindex c046869d0f..6ca2b3012e 100644--- a/apps/desktop/src/stores/queryStore.ts+++ b/apps/desktop/src/stores/queryStore.ts@@ -1775,6 +1775,8 @@ export const useQueryStore = defineStore("query", () => {tab.resultPageSql = undefined;tab.resultPageLimit = undefined;tab.resultPageOffset = undefined;+ tab.resultExecutedPageLimit = undefined;+ tab.resultExecutedPageOffset = undefined;tab.resultCountSql = undefined;tab.resultTotalRowCount = undefined;tab.resultTotalRowCountLoading = false;@@ -1856,6 +1858,8 @@ export const useQueryStore = defineStore("query", () => {tab.resultPageSql = run.resultPageSql;tab.resultPageLimit = run.resultPageLimit;tab.resultPageOffset = run.resultPageOffset;+ tab.resultExecutedPageLimit = run.resultExecutedPageLimit;+ tab.resultExecutedPageOffset = run.resultExecutedPageOffset;tab.resultCountSql = run.resultCountSql;tab.resultTotalRowCount = run.resultTotalRowCount;tab.resultTotalRowCountLoading = run.resultTotalRowCountLoading;@@ -2131,6 +2135,8 @@ export const useQueryStore = defineStore("query", () => {resultPageSql: run.resultPageSql,resultPageLimit: run.resultPageLimit,resultPageOffset: run.resultPageOffset,+ resultExecutedPageLimit: run.resultExecutedPageLimit,+ resultExecutedPageOffset: run.resultExecutedPageOffset,resultCountSql: run.resultCountSql,resultTotalRowCount: run.resultTotalRowCount,cachedAt: Date.now(),@@ -2199,6 +2205,8 @@ export const useQueryStore = defineStore("query", () => {resultPageSql: tab.resultPageSql,resultPageLimit: tab.resultPageLimit,resultPageOffset: tab.resultPageOffset,+ resultExecutedPageLimit: tab.resultExecutedPageLimit,+ resultExecutedPageOffset: tab.resultExecutedPageOffset,resultCountSql: tab.resultCountSql,resultTotalRowCount: tab.resultTotalRowCount,resultTotalRowCountLoading: tab.resultTotalRowCountLoading,@@ -2306,6 +2314,8 @@ export const useQueryStore = defineStore("query", () => {resultPageSql: tab.resultPageSql,resultPageLimit: tab.resultPageLimit,resultPageOffset: tab.resultPageOffset,+ resultExecutedPageLimit: tab.resultExecutedPageLimit,+ resultExecutedPageOffset: tab.resultExecutedPageOffset,resultCountSql: tab.resultCountSql,resultTotalRowCount: tab.resultTotalRowCount,resultTotalRowCountLoading: tab.resultTotalRowCountLoading,@@ -4647,6 +4657,8 @@ export const useQueryStore = defineStore("query", () => {resultPageSql: undefined,resultPageLimit: undefined,resultPageOffset: undefined,+ resultExecutedPageLimit: undefined,+ resultExecutedPageOffset: undefined,resultCountSql: undefined,resultTotalRowCount: undefined,resultTotalRowCountLoading: undefined,@@ -7513,6 +7525,8 @@ export const useQueryStore = defineStore("query", () => {current.resultPageSql = undefined;current.resultPageLimit = mongoFindPageState?.pageLimit;current.resultPageOffset = shouldAppendResult ? (current.resultPageOffset ?? 0) : mongoFindPageState?.pageOffset;+ current.resultExecutedPageLimit = mongoFindPageState?.pageLimit;+ current.resultExecutedPageOffset = mongoFindPageState?.pageOffset;current.resultCountSql = undefined;current.resultSessionId = undefined;current.resultClientSessionId = undefined;@@ -8029,6 +8043,10 @@ export const useQueryStore = defineStore("query", () => {const displayPageLimit = typeof pageLimit === "number" ? (requestedPageLimit ?? pageLimit) : undefined;current.resultPageLimit = shouldAppendResult ? (current.resultPageLimit ?? displayPageLimit) : displayPageLimit;current.resultPageOffset = shouldAppendResult ? (current.resultPageOffset ?? 0) : pageOffset;+ // An appended segment keeps the base page above, but the SQL shown for the+ // grid has to describe the segment that actually ran.+ current.resultExecutedPageLimit = pageLimit;+ current.resultExecutedPageOffset = pageOffset;current.resultCountSql = countSql;current.resultSessionId = current.result?.session_id ?? undefined;current.resultClientSessionId = current.resultSessionId ? executionClientSessionId : undefined;@@ -8205,6 +8223,8 @@ export const useQueryStore = defineStore("query", () => {current.resultPageSql = pageSql;current.resultPageLimit = typeof pageLimit === "number" ? (requestedPageLimit ?? pageLimit) : undefined;current.resultPageOffset = pageOffset;+ current.resultExecutedPageLimit = pageLimit;+ current.resultExecutedPageOffset = pageOffset;current.resultCountSql = countSql;current.resultSessionId = undefined;current.resultClientSessionId = undefined;@@ -8881,6 +8901,8 @@ export const useQueryStore = defineStore("query", () => {// Restoring this state must not change the global page-size defaults.tab.resultPageLimit = snapshot.resultPageLimit;tab.resultPageOffset = snapshot.resultPageOffset;+ tab.resultExecutedPageLimit = snapshot.resultExecutedPageLimit;+ tab.resultExecutedPageOffset = snapshot.resultExecutedPageOffset;tab.resultCountSql = snapshot.resultCountSql;tab.resultTotalRowCount = snapshot.resultTotalRowCount;tab.resultTotalRowCountLoading = false;diff --git a/apps/desktop/src/types/database.ts b/apps/desktop/src/types/database.tsindex fd95de578a..9e08edb4b5 100644--- a/apps/desktop/src/types/database.ts+++ b/apps/desktop/src/types/database.ts@@ -1440,6 +1440,8 @@ export interface QueryResultRun {resultPageSql?: string;resultPageLimit?: number;resultPageOffset?: number;+ resultExecutedPageLimit?: number;+ resultExecutedPageOffset?: number;resultCountSql?: string;resultTotalRowCount?: number;resultTotalRowCountLoading?: boolean;@@ -1913,6 +1915,15 @@ export interface QueryTab {resultPageSql?: string;resultPageLimit?: number;resultPageOffset?: number;+ /**+ * Pagination of the execution that actually produced (or extended) the+ * displayed result. `resultPageLimit`/`resultPageOffset` deliberately stay on+ * the logical first page so a later refresh never re-runs only the appended+ * tail segment; this pair mirrors the segment that ran instead, which the grid+ * needs to show the SQL behind the current rows after "load all".+ */+ resultExecutedPageLimit?: number;+ resultExecutedPageOffset?: number;resultCountSql?: string;resultTotalRowCount?: number;resultTotalRowCountLoading?: boolean;diff --git a/packages/app-tests/dataGridPagination.test.ts b/packages/app-tests/dataGridPagination.test.tsindex 57aa8a6974..5d7fcaf804 100644--- a/packages/app-tests/dataGridPagination.test.ts+++ b/packages/app-tests/dataGridPagination.test.ts@@ -1,6 +1,6 @@import { strict as assert } from "node:assert";import { test } from "vitest";-import { canFetchNextDataGridSegment, canGoNextDataGridPage, dataGridLoadAllSegment, hasCompleteLocalDataGridResult, resolveDataGridPaginationTotal } from "../../apps/desktop/src/lib/dataGrid/dataGridPagination.ts";+import { canFetchNextDataGridSegment, canGoNextDataGridPage, dataGridLoadAllSegment, dataGridUserFacingPage, hasCompleteLocalDataGridResult, resolveDataGridPaginationTotal } from "../../apps/desktop/src/lib/dataGrid/dataGridPagination.ts";test("estimated display totals do not become pagination bounds", () => {assert.equal(@@ -244,3 +244,23 @@ test("auto-redirect: total is undefined — guard prevents redirect attempt", ()const total = undefined;assert.equal(!total || (total as any) <= 0, true, "guard should prevent redirect when total is unknown");});++test("the SQL shown under the grid describes the segment that actually ran", () => {+ // "Load all" keeps resultPageLimit/Offset on the logical first page, so the+ // footer has to read the executed segment instead of claiming LIMIT 100.+ assert.deepEqual(+ dataGridUserFacingPage({+ executedPageLimit: 99_900,+ executedPageOffset: 100,+ pageLimit: 100,+ pageOffset: 0,+ fallbackLimit: 100,+ fallbackOffset: 0,+ }),+ { limit: 99_900, offset: 100 },+ );+ assert.deepEqual(dataGridUserFacingPage({ executedPageLimit: 100, executedPageOffset: 200, pageLimit: 100, pageOffset: 200, fallbackLimit: 100, fallbackOffset: 0 }), { limit: 100, offset: 200 });+ // Snapshots written before the executed page existed fall back to the page props.+ assert.deepEqual(dataGridUserFacingPage({ pageLimit: 50, pageOffset: 150, fallbackLimit: 100, fallbackOffset: 0 }), { limit: 50, offset: 150 });+ assert.deepEqual(dataGridUserFacingPage({ fallbackLimit: 100, fallbackOffset: 300 }), { limit: 100, offset: 300 });+});diff --git a/packages/app-tests/queryStore.test.ts b/packages/app-tests/queryStore.test.tsindex e63b2f2c9f..855d26629d 100644--- a/packages/app-tests/queryStore.test.ts+++ b/packages/app-tests/queryStore.test.ts@@ -4818,6 +4818,8 @@ test("data tab execution preserves pagination offset metadata", async () => {assert.equal(executeBody.schema, undefined);assert.equal(tab.resultPageLimit, 100);assert.equal(tab.resultPageOffset, 100);+ assert.equal(tab.resultExecutedPageLimit, 100);+ assert.equal(tab.resultExecutedPageOffset, 100);assert.deepEqual(tab.result?.rows, [[101]]);} finally {globalThis.fetch = originalFetch;@@ -4881,6 +4883,8 @@ test("append pagination preserves existing rows and respects the memory cap", asassert.equal(tab.result?.has_more, false);assert.equal(tab.resultPageOffset, 0, "later refreshes must restart from the logical result origin");assert.equal(tab.resultPageLimit, 1000, "a short appended segment must preserve the base display page size");+ assert.equal(tab.resultExecutedPageOffset, 1, "the SQL shown for the grid describes the appended segment");+ assert.equal(tab.resultExecutedPageLimit, 2);} finally {globalThis.fetch = originalFetch;restoreStorage();