fix(grid): budget large-value previews by segment and show executed SQL
This commit is contained in:
12 files changed
+194
-10
No files matched your search
@@ -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" });
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user