11 files changed
+505
-35
No files matched your search
@@ -95,7 +95,7 @@ import { queryResultNameFromPreamble, queryResultSourceLabel, queryResultSourceN
|
||||
import { sqlServerCountUsesLocalTempTable } from "@/lib/query/queryResultCountSession";
|
||||
import { stripPaginationRowNumber } from "@/lib/query/queryPaginationResult";
|
||||
import { beginDataGridNativeSelectionBlock, finishDataGridNativeSelectionBlock } from "@/lib/dataGrid/dataGridNativeSelection";
|
||||
import { appendLargeValueCells, canUseTableDataLargeValuePreview, remapLargeValueCells, tableDataLargeValuePreviewOptions, TABLE_DATA_RESULT_MAX_BYTES } from "@/lib/dataGrid/dataGridLargeValues";
|
||||
import { appendLargeValueCells, canUseTableDataLargeValuePreview, remapLargeValueCells, supportsTableDataLargeValuePreview, tableDataLargeValuePreviewOptions, TABLE_DATA_RESULT_MAX_BYTES } from "@/lib/dataGrid/dataGridLargeValues";
|
||||
import { simpleDataGridOrderByReferencesMissingColumn, sortDataGridRowIndexes, type DataGridSortDirection } from "@/lib/dataGrid/dataGridSort";
|
||||
import { normalizeResultPageSize } from "@/lib/dataGrid/paginationPageSize";
|
||||
import { agentProtocolQueryResultMaxRows, capQueryResultTotal, effectiveQueryResultMaxRows, limitQueryPagination, queryResultLimitReached } from "@/lib/dataGrid/queryResultRowLimit";
|
||||
@@ -148,6 +148,7 @@ const QUERY_SURFACE_ACTIVATION_EVENT = "dbx:activate-query-surface";
|
||||
|
||||
const ORACLE_LIKE_METADATA_TYPES = new Set<string>(["oracle", "dameng", "oceanbase-oracle"]);
|
||||
const ORACLE_DEFERRED_LOB_TYPES = new Set<string>(["CLOB", "NCLOB", "BLOB", "BFILE", "XMLTYPE", "SYS.XMLTYPE"]);
|
||||
const DB2_DEFERRED_LOB_TYPES = new Set<string>(["CLOB", "DBCLOB", "BLOB"]);
|
||||
|
||||
// Bounded concurrency for grouped-query display column loads, scoped per
|
||||
// connection so different connections never block each other. Matches the
|
||||
@@ -163,7 +164,7 @@ const UPPERCASE_FOLDED_METADATA_TYPES = new Set<string>([...ORACLE_LIKE_METADATA
|
||||
// OceanBase Oracle mode ride the Oracle adapter and HighGo rides the PostgreSQL one
|
||||
// (issue #10233: without this, a query that omits the primary key stays read-only
|
||||
// even though the table has one).
|
||||
const HIDDEN_QUERY_KEY_DATABASE_TYPES = new Set<DatabaseType>(["mysql", "postgres", "sqlserver", "oracle", "xugu", "dameng", "highgo", "oceanbase-oracle"]);
|
||||
const HIDDEN_QUERY_KEY_DATABASE_TYPES = new Set<DatabaseType>(["mysql", "postgres", "sqlserver", "oracle", "xugu", "dameng", "highgo", "oceanbase-oracle", "db2"]);
|
||||
const QUERY_RESULT_EXPORT_UNSUPPORTED_ERROR = "Streaming export is unsupported for this query. Simplify it or use a supported driver.";
|
||||
const BACKGROUND_CLIENT_SESSION_SUFFIXES = ["count", "explain", "export"] as const;
|
||||
const CANCEL_QUERY_TIMEOUT_MS = 10_000;
|
||||
@@ -838,14 +839,23 @@ function projectsAllColumnsForSource(analysis: EditableQueryInfo, sourceKey: str
|
||||
return analysis.selectStar || analysis.columns.some((column) => column.star && (!column.sourceKey || column.sourceKey === sourceKey));
|
||||
}
|
||||
|
||||
function oracleQueryProjectsDeferredLob(analysis: EditableQueryInfo, sourceKey: string, columns: readonly { name: string; data_type: string }[]): boolean {
|
||||
const deferredColumns = new Set(columns.filter((column) => ORACLE_DEFERRED_LOB_TYPES.has(column.data_type.trim().toUpperCase())).map((column) => column.name.toLowerCase()));
|
||||
function queryProjectsDeferredLob(databaseType: DatabaseType, analysis: EditableQueryInfo, sourceKey: string, columns: readonly { name: string; data_type: string }[]): boolean {
|
||||
const deferredTypes = databaseType === "oracle" ? ORACLE_DEFERRED_LOB_TYPES : databaseType === "db2" ? DB2_DEFERRED_LOB_TYPES : undefined;
|
||||
if (!deferredTypes) return false;
|
||||
const deferredColumns = new Set(
|
||||
columns
|
||||
.filter((column) => {
|
||||
const normalized = column.data_type.trim().toUpperCase();
|
||||
return deferredTypes.has(normalized) || deferredTypes.has(normalized.split("(", 1)[0]!.trim());
|
||||
})
|
||||
.map((column) => column.name.toLowerCase()),
|
||||
);
|
||||
if (deferredColumns.size === 0) return false;
|
||||
if (projectsAllColumnsForSource(analysis, sourceKey)) return true;
|
||||
return analysis.columns.some((column) => column.sourceName && column.sourceKey === sourceKey && deferredColumns.has(column.sourceName.toLowerCase()));
|
||||
}
|
||||
|
||||
function oracleColumnsAllowDeferredLobMarkers(columns: readonly { name: string }[]): boolean {
|
||||
function columnsAllowDeferredLobMarkers(columns: readonly { name: string }[]): boolean {
|
||||
return !columns.some((column) => column.name.toUpperCase().startsWith("__DBX_LARGE_VALUE_BYTES_"));
|
||||
}
|
||||
|
||||
@@ -5961,7 +5971,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
sql: string;
|
||||
metadataSql: string;
|
||||
hiddenPrimaryKeys: HiddenPrimaryKeyProjection[];
|
||||
oracleLobPreview: boolean;
|
||||
largeValuePreview: boolean;
|
||||
}
|
||||
|
||||
function oracleCompletionTableType(tab: QueryTab, metadataDbType: string, database: string, schema: string, tableName: string, catalog?: string): string | undefined {
|
||||
@@ -6215,8 +6225,9 @@ export const useQueryStore = defineStore("query", () => {
|
||||
|
||||
function buildHiddenPrimaryKeyPreparation(tab: QueryTab, sql: string, databaseType: DatabaseType, loaded: LoadedEditableSource, primaryKeys: string[], declaredPrimaryKeys: string[], traceId: string, elapsed: () => string): EditableQueryExecutionPreparation {
|
||||
const metadataAnalysis = expandStarProjectionColumnsForSource(bindColumnsForSource(databaseType, loaded.analysis, loaded.source, loaded.tableMeta.columns), loaded.source, loaded.tableMeta.columns);
|
||||
const oracleLobPreview = databaseType === "oracle" && primaryKeys.length > 0 && oracleRowIdIsSafeForQuery(tab, loaded) && oracleColumnsAllowDeferredLobMarkers(loaded.tableMeta.columns) && oracleQueryProjectsDeferredLob(metadataAnalysis, loaded.source.key, loaded.tableMeta.columns);
|
||||
const unchanged = { sql, metadataSql: sql, hiddenPrimaryKeys: [], oracleLobPreview };
|
||||
const stableLobSource = databaseType === "oracle" ? oracleRowIdIsSafeForQuery(tab, loaded) : databaseType === "db2";
|
||||
const largeValuePreview = (databaseType === "oracle" || databaseType === "db2") && primaryKeys.length > 0 && stableLobSource && columnsAllowDeferredLobMarkers(loaded.tableMeta.columns) && queryProjectsDeferredLob(databaseType, metadataAnalysis, loaded.source.key, loaded.tableMeta.columns);
|
||||
const unchanged = { sql, metadataSql: sql, hiddenPrimaryKeys: [], largeValuePreview };
|
||||
const missingPrimaryKeys =
|
||||
declaredPrimaryKeys.length === 0
|
||||
? primaryKeys.filter((primaryKey) => !(databaseType === "oracle" && primaryKey === DBX_ROWID_COLUMN && metadataAnalysis.columns.some((column) => column.sourceKey === loaded.source.key && !column.sourceNameQuoted && column.sourceName?.toUpperCase() === "ROWID")))
|
||||
@@ -6240,11 +6251,11 @@ export const useQueryStore = defineStore("query", () => {
|
||||
keyCount: rewritten.projections.length,
|
||||
elapsed: elapsed(),
|
||||
});
|
||||
return { sql: rewritten.sql, metadataSql: rewritten.sql, hiddenPrimaryKeys: rewritten.projections, oracleLobPreview };
|
||||
return { sql: rewritten.sql, metadataSql: rewritten.sql, hiddenPrimaryKeys: rewritten.projections, largeValuePreview };
|
||||
}
|
||||
|
||||
async function prepareEditableQueryExecution(tab: QueryTab, sql: string, conn: ConnectionConfig | undefined, databaseType: DatabaseType | undefined, executionDatabase: string, traceId: string, elapsed: () => string): Promise<EditableQueryExecutionPreparation> {
|
||||
const unchanged = { sql, metadataSql: sql, hiddenPrimaryKeys: [], oracleLobPreview: false };
|
||||
const unchanged = { sql, metadataSql: sql, hiddenPrimaryKeys: [], largeValuePreview: false };
|
||||
if (!databaseType || !HIDDEN_QUERY_KEY_DATABASE_TYPES.has(databaseType) || !tab.connectionId) return unchanged;
|
||||
|
||||
try {
|
||||
@@ -6257,10 +6268,10 @@ export const useQueryStore = defineStore("query", () => {
|
||||
const wholeSourceProjected = projectsAllColumnsForSource(analysis, source.key);
|
||||
const hasDirectSourceProjection = analysis.columns.some((column) => Boolean(column.sourceName) && (!column.sourceKey || column.sourceKey === source.key));
|
||||
if (!wholeSourceProjected && !hasDirectSourceProjection) return unchanged;
|
||||
// Whole-source projections already include declared primary keys. Only
|
||||
// Oracle and Xugu need preflight metadata here to add their synthetic
|
||||
// row key for a keyless base table.
|
||||
if (databaseType !== "oracle" && databaseType !== "xugu" && wholeSourceProjected) return unchanged;
|
||||
// Whole-source projections already include declared primary keys. Oracle
|
||||
// and Xugu may need a synthetic key, while DB2 needs column metadata to
|
||||
// decide whether LOB materialization can be deferred safely.
|
||||
if (databaseType !== "oracle" && databaseType !== "xugu" && databaseType !== "db2" && wholeSourceProjected) return unchanged;
|
||||
|
||||
const target = resolveEditableSourceMetadataTarget(tab, analysis, source, conn, databaseType, executionDatabase);
|
||||
const cached = getCachedTableMetadata(target.request);
|
||||
@@ -6951,7 +6962,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
let resultSortedSql = options?.resultSortedSql;
|
||||
let queryMetadataSql = queryBaseSql;
|
||||
let hiddenPrimaryKeys: HiddenPrimaryKeyProjection[] = [];
|
||||
let useOracleLobPreview = false;
|
||||
let useLargeValuePreview = false;
|
||||
let pageSql: string | undefined;
|
||||
let requestedPageLimit: number | undefined;
|
||||
let pageLimit: number | undefined;
|
||||
@@ -7703,7 +7714,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
// does not turn an otherwise editable result into a complex read-only one.
|
||||
queryMetadataSql = options?.resultSortedSql && !options?.querySort ? queryBaseSql : prepared.metadataSql;
|
||||
hiddenPrimaryKeys = prepared.hiddenPrimaryKeys;
|
||||
useOracleLobPreview = prepared.oracleLobPreview;
|
||||
useLargeValuePreview = prepared.largeValuePreview;
|
||||
if (options?.querySort) {
|
||||
const sorted = await api.buildSortedQuerySql({
|
||||
originalSql: sqlToExecute,
|
||||
@@ -7816,14 +7827,14 @@ export const useQueryStore = defineStore("query", () => {
|
||||
: { maxRows: agentProtocolQueryResultMaxRows(queryResultMaxRows) }),
|
||||
...(useJdbcDriverRowOffset && typeof pageOffset === "number" && pageOffset > 0 ? { rowOffset: pageOffset } : {}),
|
||||
...(executionClientSessionId ? { clientSessionId: executionClientSessionId } : {}),
|
||||
...(tab.mode === "data" && (effectiveDbType === "mysql" || effectiveDbType === "postgres")
|
||||
...(tab.mode === "data" && supportsTableDataLargeValuePreview(effectiveDbType)
|
||||
? {
|
||||
maxResultBytes: TABLE_DATA_RESULT_MAX_BYTES,
|
||||
resultKeyColumns: dataTabMeta?.primaryKeys ?? [],
|
||||
tableDataPreview: useTableDataPreview,
|
||||
}
|
||||
: {}),
|
||||
...(useOracleLobPreview ? { tableDataPreview: true } : {}),
|
||||
...(useLargeValuePreview ? { tableDataPreview: true } : {}),
|
||||
timeoutSecs: queryTimeoutSecs,
|
||||
catalog: executionCatalog,
|
||||
continueOnError: continueOnBatchError,
|
||||
@@ -7953,8 +7964,8 @@ export const useQueryStore = defineStore("query", () => {
|
||||
// strand it after returning the first page.
|
||||
const executeInTransaction = (sessionId: string) =>
|
||||
useAgentResultSession && !isOffsetJumpPage
|
||||
? api.executeInManualTransaction(sessionId, sqlToExecute, executionDatabase, executionSchema, agentProtocolQueryResultMaxRows(queryResultMaxRows), useOracleLobPreview, pageLimit, options?.pagination?.sessionId, classificationSql)
|
||||
: api.executeInManualTransaction(sessionId, sqlToExecute, executionDatabase, executionSchema, pageLimit ?? agentProtocolQueryResultMaxRows(queryResultMaxRows), useOracleLobPreview, undefined, undefined, classificationSql);
|
||||
? api.executeInManualTransaction(sessionId, sqlToExecute, executionDatabase, executionSchema, agentProtocolQueryResultMaxRows(queryResultMaxRows), useLargeValuePreview, pageLimit, options?.pagination?.sessionId, classificationSql)
|
||||
: api.executeInManualTransaction(sessionId, sqlToExecute, executionDatabase, executionSchema, pageLimit ?? agentProtocolQueryResultMaxRows(queryResultMaxRows), useLargeValuePreview, undefined, undefined, classificationSql);
|
||||
try {
|
||||
return await executeInTransaction(txnSessionId);
|
||||
} catch (error) {
|
||||
|
||||
Reference in new issue
Block a user