Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(sql-editor): custom result rows limit and result page size (#11822)

Liu Ji13d8e73e3815
diff --git a/frontend/src/components/v2/Model/DatabaseV1Table/cells/DatabaseNameCell.vue b/frontend/src/components/v2/Model/DatabaseV1Table/cells/DatabaseNameCell.vue
index 92ba1d2b3c..daf25abefb 100644
--- a/frontend/src/components/v2/Model/DatabaseV1Table/cells/DatabaseNameCell.vue
+++ b/frontend/src/components/v2/Model/DatabaseV1Table/cells/DatabaseNameCell.vue
@@ -12,7 +12,6 @@
</template>
<script setup lang="ts">
-import { defineProps } from "vue";
import SQLEditorButtonV1 from "@/components/DatabaseDetail/SQLEditorButtonV1.vue";
import { DatabaseV1Name } from "@/components/v2";
import { pushNotification, useCurrentUserV1 } from "@/store";
diff --git a/frontend/src/composables/useExecuteSQL.ts b/frontend/src/composables/useExecuteSQL.ts
index eb2006e964..bbc31f205e 100644
--- a/frontend/src/composables/useExecuteSQL.ts
+++ b/frontend/src/composables/useExecuteSQL.ts
@@ -9,7 +9,6 @@ import {
useDatabaseV1Store,
useSQLEditorStore,
useSQLEditorTabStore,
- RESULT_ROWS_LIMIT,
useSQLStore,
useSQLEditorQueryHistoryStore,
} from "@/store";
@@ -182,7 +181,7 @@ const useExecuteSQL = () => {
connectionDatabase: database.databaseName, // deprecated field, remove me later
dataSourceId: dataSourceId,
statement,
- limit: RESULT_ROWS_LIMIT,
+ limit: sqlEditorStore.resultRowsLimit,
},
abortController.signal
);
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 8061d1b141..8a56a548ef 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2270,7 +2270,12 @@
"sync-in-progress": "Sync in progress",
"create-a-worksheet": "Create a new worksheet",
"select-a-database-to-start": "Select a database to start",
- "select-encoding": "Select encoding"
+ "select-encoding": "Select encoding",
+ "result-limit": {
+ "n-rows": "{n} rows",
+ "rows": "rows"
+ },
+ "n-per-page": "{n} / page"
},
"schema-editor": {
"self": "Schema Editor",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 2ee0d28612..e614f9f986 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2270,7 +2270,12 @@
"sync-in-progress": "Sincronización en progreso",
"create-a-worksheet": "Crear una hoja de trabajo",
"select-a-database-to-start": "Seleccione una base de datos para comenzar",
- "select-encoding": "Seleccionar codificación"
+ "select-encoding": "Seleccionar codificación",
+ "result-limit": {
+ "n-rows": "{n} filas",
+ "rows": "filas"
+ },
+ "n-per-page": "{n} / página"
},
"schema-editor": {
"self": "Editor de esquema",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 7d45ce6144..da6e7f4721 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -2270,7 +2270,12 @@
"sync-in-progress": "同期中",
"create-a-worksheet": "新しいワークシートを作成する",
"select-a-database-to-start": "開始するにはデータベースを選択してください",
- "select-encoding": "エンコーディングの選択"
+ "select-encoding": "エンコーディングの選択",
+ "result-limit": {
+ "n-rows": "{n} 行",
+ "rows": "行"
+ },
+ "n-per-page": "{n} / ページ"
},
"schema-editor": {
"self": "スキーマエディタ",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 7849bda9b5..110e605c7a 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -2270,7 +2270,12 @@
"sync-in-progress": "Đang đồng bộ hóa",
"create-a-worksheet": "Tạo một bảng tính",
"select-a-database-to-start": "Chọn cơ sở dữ liệu để bắt đầu",
- "select-encoding": "Chọn mã hóa"
+ "select-encoding": "Chọn mã hóa",
+ "result-limit": {
+ "n-rows": "{n} hàng",
+ "rows": "hàng"
+ },
+ "n-per-page": "{n} / trang"
},
"schema-editor": {
"self": "Trình chỉnh sửa lược đồ",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index c912e2970b..500384c3bb 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2270,7 +2270,12 @@
"sync-in-progress": "正在同步",
"create-a-worksheet": "新建工作表",
"select-a-database-to-start": "选择数据库以开始",
- "select-encoding": "选择编码"
+ "select-encoding": "选择编码",
+ "result-limit": {
+ "n-rows": "{n} 行",
+ "rows": "行"
+ },
+ "n-per-page": "{n} / 页"
},
"schema-editor": {
"self": "Schema 编辑器",
diff --git a/frontend/src/store/modules/sqlEditor/editor.ts b/frontend/src/store/modules/sqlEditor/editor.ts
index 61b874a446..eb642b719a 100644
--- a/frontend/src/store/modules/sqlEditor/editor.ts
+++ b/frontend/src/store/modules/sqlEditor/editor.ts
@@ -6,10 +6,12 @@ import { hasWorkspacePermissionV2 } from "@/utils";
import { useCurrentUserV1 } from "../auth";
import { useProjectV1Store } from "../v1";
-// set the limit to 1000 temporarily to avoid the query timeout and page crash
-export const RESULT_ROWS_LIMIT = 1000;
-
export const useSQLEditorStore = defineStore("sqlEditor", () => {
+ const resultRowsLimit = useLocalStorage(
+ "bb.sql-editor.result-rows-limit",
+ 1000
+ );
+
// empty to "ALL" projects for high-privileged users
const project = ref<string>("");
// if `true`, won't show project selector and not allowed to switch to other projects
@@ -43,6 +45,7 @@ export const useSQLEditorStore = defineStore("sqlEditor", () => {
const isShowExecutingHint = ref(false);
return {
+ resultRowsLimit,
project,
strictProject,
projectContextReady,
diff --git a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
index 55baa9f259..1f9d193a28 100644
--- a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
@@ -48,6 +48,7 @@
({{ keyboardShortcutStr("shift+opt_or_alt+C") }})
</span>
</NButton>
+ <ResultLimitSelect />
</div>
<div
class="action-right gap-x-2 flex overflow-x-auto sm:overflow-x-hidden sm:justify-end items-center"
@@ -123,6 +124,7 @@ import { keyboardShortcutStr } from "@/utils";
import { useSQLEditorContext } from "../context";
import AdminModeButton from "./AdminModeButton.vue";
import QueryContextSettingPopover from "./QueryContextSettingPopover.vue";
+import ResultLimitSelect from "./ResultLimitSelect.vue";
import SharePopover from "./SharePopover.vue";
interface LocalState {
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultLimitSelect.vue b/frontend/src/views/sql-editor/EditorCommon/ResultLimitSelect.vue
new file mode 100644
index 0000000000..f959b38701
--- /dev/null
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultLimitSelect.vue
@@ -0,0 +1,44 @@
+<template>
+ <NPopselect
+ v-model:value="resultRowsLimit"
+ :options="options"
+ trigger="click"
+ placement="bottom-start"
+ scrollable
+ >
+ <NButton size="small">
+ {{ $t("sql-editor.result-limit.n-rows", { n: resultRowsLimit }) }}
+ </NButton>
+ <template #action>
+ <div class="flex items-center justify-between gap-1">
+ <NInputNumber
+ v-model:value="resultRowsLimit"
+ :show-button="false"
+ :min="0"
+ :max="100000"
+ style="width: 5rem"
+ size="small"
+ />
+ <span>{{ $t("sql-editor.result-limit.rows") }}</span>
+ </div>
+ </template>
+ </NPopselect>
+</template>
+
+<script setup lang="ts">
+import { NButton, NInputNumber, type SelectOption } from "naive-ui";
+import { storeToRefs } from "pinia";
+import { computed } from "vue";
+import { useI18n } from "vue-i18n";
+import { useSQLEditorStore } from "@/store";
+
+const { t } = useI18n();
+const { resultRowsLimit } = storeToRefs(useSQLEditorStore());
+
+const options = computed((): SelectOption[] => {
+ return [100, 500, 1000, 5000, 10000, 100000].map((n) => ({
+ label: t("sql-editor.result-limit.n-rows", { n }),
+ value: n,
+ }));
+});
+</script>
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
index 72cfd7b2c0..8b472b92b5 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
@@ -22,7 +22,8 @@
}}</span>
<span
v-if="
- currentTab?.mode !== 'ADMIN' && data.length === RESULT_ROWS_LIMIT
+ currentTab?.mode !== 'ADMIN' &&
+ data.length === editorStore.resultRowsLimit
"
class="ml-2 whitespace-nowrap text-sm text-gray-500"
>
@@ -43,8 +44,22 @@
:item-count="table.getCoreRowModel().rows.length"
:page="pageIndex + 1"
:page-size="pageSize"
+ class="pagination"
+ style="--n-input-width: 2.5rem"
@update-page="handleChangePage"
- />
+ >
+ <template #suffix>
+ <NSelect
+ v-model:value="pageSize"
+ :options="pageSizeOptions"
+ :consistent-menu-width="false"
+ :show-arrow="false"
+ class="pagesize-select"
+ placement="bottom-end"
+ size="small"
+ />
+ </template>
+ </NPagination>
<NButton
v-if="showVisualizeButton"
text
@@ -151,10 +166,18 @@ import {
getSortedRowModel,
useVueTable,
} from "@tanstack/vue-table";
-import { useDebounceFn } from "@vueuse/core";
+import { useDebounceFn, useLocalStorage } from "@vueuse/core";
import { isEmpty } from "lodash-es";
import { ExternalLinkIcon } from "lucide-vue-next";
-import { NButton, NInput, NSwitch, NPagination, NTooltip } from "naive-ui";
+import {
+ NButton,
+ NInput,
+ NSwitch,
+ NPagination,
+ NTooltip,
+ type SelectOption,
+ NSelect,
+} from "naive-ui";
import type { BinaryLike } from "node:crypto";
import { computed, reactive } from "vue";
import { useI18n } from "vue-i18n";
@@ -164,11 +187,11 @@ import { DISMISS_PLACEHOLDER } from "@/plugins/ai/components/state";
import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
import {
useSQLEditorTabStore,
- RESULT_ROWS_LIMIT,
featureToRef,
useCurrentUserV1,
useActuatorV1Store,
useConnectionOfCurrentSQLEditorTab,
+ useSQLEditorStore,
} from "@/store";
import { useExportData } from "@/store/modules/export";
import type {
@@ -206,8 +229,11 @@ type LocalState = {
};
type ViewMode = "RESULT" | "EMPTY" | "AFFECTED-ROWS" | "ERROR";
-const PAGE_SIZES = [20, 50, 100];
const DEFAULT_PAGE_SIZE = 50;
+const storedPageSize = useLocalStorage<number>(
+ "bb.sql-editor.result-page-size",
+ DEFAULT_PAGE_SIZE
+);
const props = defineProps<{
params: SQLEditorQueryParams;
@@ -227,6 +253,7 @@ const router = useRouter();
const { dark, keyword } = useSQLResultViewContext();
const actuatorStore = useActuatorV1Store();
const tabStore = useSQLEditorTabStore();
+const editorStore = useSQLEditorStore();
const currentUserV1 = useCurrentUserV1();
const { exportData } = useExportData();
const currentTab = computed(() => tabStore.currentTab);
@@ -350,13 +377,25 @@ const table = useVueTable<QueryRow>({
getPaginationRowModel: getPaginationRowModel(),
});
-table.setPageSize(DEFAULT_PAGE_SIZE);
+table.setPageSize(storedPageSize.value);
const pageIndex = computed(() => {
return table.getState().pagination.pageIndex;
});
-const pageSize = computed(() => {
- return table.getState().pagination.pageSize;
+const pageSize = computed({
+ get() {
+ return table.getState().pagination.pageSize;
+ },
+ set(ps) {
+ table.setPageSize(ps);
+ storedPageSize.value = ps;
+ },
+});
+const pageSizeOptions = computed(() => {
+ return [20, 50, 100, 1000].map<SelectOption>((n) => ({
+ label: t("sql-editor.n-per-page", { n }),
+ value: n,
+ }));
});
const handleExportBtnClick = async (
@@ -377,7 +416,7 @@ const handleExportBtnClick = async (
: connectedInstance.value.name;
const statement = props.result.statement;
const admin = tabStore.currentTab?.mode === "ADMIN";
- const limit = options.limit ?? (admin ? 0 : RESULT_ROWS_LIMIT);
+ const limit = options.limit ?? (admin ? 0 : editorStore.resultRowsLimit);
const content = await exportData({
database,
@@ -442,7 +481,7 @@ const visualizeExplain = () => {
}
};
-const showPagination = computed(() => data.value.length > PAGE_SIZES[0]);
+const showPagination = computed(() => data.value.length > pageSize.value);
const handleChangePage = (page: number) => {
table.setPageIndex(page - 1);
@@ -470,3 +509,18 @@ const queryTime = computed(() => {
return `${totalSeconds.toFixed(2)} s`;
});
</script>
+
+<style scoped lang="postcss">
+.pagination :deep(.n-input) {
+ --n-padding-left: 6px !important;
+ --n-padding-right: 6px !important;
+}
+.pagination :deep(.n-input__input-el) {
+ text-align: right;
+}
+
+.pagesize-select :deep(.n-base-selection) {
+ --n-padding-single-left: 8px !important;
+ --n-padding-single-right: 8px !important;
+}
+</style>
\ No newline at end of file