Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/adr/0005-parser-independent-relation-completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ The initial checked limits are:
| Lexical tokens | 16,384 |
| Parenthesis/query depth | 128 |
| CTE declarations | 256 |
| Identifier path segments | 4 |
| Identifier path segments | 32 global ceiling; dialect runtime sets the checked limit |
| Identifier segment | 256 UTF-16 units |
| Catalog scope | 512 UTF-16 units |
| Search paths | 32 |
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"test:worker-placement": "node ./scripts/worker-placement.mjs",
"test:integrity": "node ./scripts/check-test-integrity.mjs",
"bench:parser-adapter": "vitest bench --run src/vnext/__tests__/node-sql-parser-adapter.bench.ts",
"bench:query-site": "vitest bench --run src/vnext/__tests__/query-site.bench.ts",
"bench:statement-index": "vitest bench --run src/vnext/__tests__/statement-index.bench.ts",
"test:package": "node ./scripts/clean.mjs && tsc && node ./scripts/package-smoke.mjs",
"demo": "vite build",
Expand Down
72 changes: 72 additions & 0 deletions src/vnext/__tests__/query-site.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { bench, describe } from "vitest";
import {
recognizeSqlRelationQuerySite,
type SqlQuerySiteDialect,
} from "../query-site.js";
import { createIdentitySqlSource } from "../source.js";
import {
buildSqlStatementIndex,
DUCKDB_SQL_LEXICAL_PROFILE,
findSqlStatementSlot,
} from "../statement-index.js";

const dialect: SqlQuerySiteDialect = {
classifyRelationAlias: (rawAlias) => ({
status: "identifier",
value: rawAlias,
}),
decodeRelationPath: (rawPath, cursorOffset) => ({
finalSegment: { from: 0, to: rawPath.length },
prefix: {
quoted: false,
value: rawPath.slice(0, cursorOffset),
},
qualifier: [],
quality: "exact",
status: "decoded",
}),
lexicalProfile: DUCKDB_SQL_LEXICAL_PROFILE,
maximumPathDepth: 16,
supportsNaturalJoin: true,
};
const tenKilobyteQuery = `SELECT ${Array.from(
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
{ length: 1_100 },
(_, index) => `value_${index}`,
).join(", ")} FROM schema_prefix`;
const source = createIdentitySqlSource(tenKilobyteQuery);
const index = buildSqlStatementIndex(
source.analysisText,
dialect.lexicalProfile,
);
const position = tenKilobyteQuery.length;
const slot = findSqlStatementSlot(index, position, "left");
const aliasHeavyQuery = `SELECT * FROM ${Array.from(
{ length: 1_000 },
(_, aliasIndex) => `table_name alias_${aliasIndex}`,
).join(", ")}, `;
const aliasHeavySource = createIdentitySqlSource(aliasHeavyQuery);
const aliasHeavyIndex = buildSqlStatementIndex(
aliasHeavySource.analysisText,
dialect.lexicalProfile,
);
const aliasHeavyPosition = aliasHeavyQuery.length;
const aliasHeavySlot = findSqlStatementSlot(
aliasHeavyIndex,
aliasHeavyPosition,
"left",
);

describe("query-site recognizer", () => {
bench("10 KiB active statement", () => {
recognizeSqlRelationQuerySite(source, slot, position, dialect);
});

bench("1,000 classified aliases", () => {
recognizeSqlRelationQuerySite(
aliasHeavySource,
aliasHeavySlot,
aliasHeavyPosition,
dialect,
);
});
});
Loading
Loading