'use client'; import { PgIdentifier } from "../sql/pg-identifier.cjs"; import { Postgres, PostgresExplainStage, PostgresTransaction } from "../sql/database.cjs"; import { FullSchemaIndex } from "../schema.cjs"; import { PostgresQueryBuilder } from "../sql/builder.cjs"; import { Statistics } from "./statistics.cjs"; import { JsonbOperator, SortContext } from "../sql/analyzer.cjs"; import { NullTestType } from "@pgsql/types"; //#region src/optimizer/genalgo.d.ts type IndexIdentifier = string; type IndexRecommendation = PermutedIndexCandidate & { definition: IndexIdentifier; }; type IndexToCreate = PermutedIndexCandidate & { name: PgIdentifier; definition: IndexIdentifier; }; declare class IndexOptimizer { private readonly db; private readonly statistics; private existingIndexes; private readonly config; static prefix: string; constructor(db: Postgres, statistics: Statistics, existingIndexes: FullSchemaIndex[], config?: { trace?: boolean; debug?: boolean; }); run(builder: PostgresQueryBuilder, indexes: RootIndexCandidate[], beforeQuery?: (tx: PostgresTransaction) => Promise): Promise; runWithoutIndexes(builder: PostgresQueryBuilder): Promise<{ Plan: PostgresExplainStage; }>; /** * Given the current indexes in the optimizer, transform them in some * way to change which indexes will be assumed to exist when optimizing * * @example * ``` * // resets indexes * optimizer.transformIndexes(() => []) * * // adds new index * optimizer.transformIndexes(indexes => [...indexes, newIndex]) * ``` */ transformIndexes(f: (indexes: FullSchemaIndex[]) => FullSchemaIndex[]): this; /** * Postgres has a limit of 63 characters for index names. * So we use this to make sure we don't derive it from a list of columns that can * overflow that limit. */ private indexName; private indexAlreadyExists; /** * Derive the list of indexes [tableA(X, Y, Z), tableB(H, I, J)] **/ private indexesToCreate; private toDefinition; private toGinDefinition; private toExpressionDefinition; private groupGinCandidatesByColumn; private ginIndexAlreadyExists; /** * Drop indexes that can be dropped. Ignore the ones that can't */ private dropExistingIndexes; private whereClause; private nullsOrder; private sortDirection; testQueryWithStats(builder: PostgresQueryBuilder, f?: (tx: PostgresTransaction) => Promise, options?: { params?: unknown[]; genericPlan?: boolean; }): Promise<{ Plan: PostgresExplainStage; }>; private groupPotentialIndexColumnsByTable; private findUsedIndexes; private replaceUsedIndexesWithDefinition; } type OptimizeResult = { kind: "ok"; baseExplainPlan: PostgresExplainStage; baseCost: number; finalCost: number; newIndexes: Set; existingIndexes: Set; triedIndexes: Map; explainPlan: PostgresExplainStage; } | { kind: "zero_cost_plan"; explainPlan: PostgresExplainStage; }; type RootIndexCandidate = { schema: string; table: string; column: string; sort?: SortContext; where?: { nulltest?: NullTestType; }; jsonbOperator?: JsonbOperator; jsonbExtraction?: string; }; type PermutedIndexCandidate = { schema: string; table: string; columns: RootIndexCandidate[]; where?: string; indexMethod?: "btree" | "gin"; opclass?: string; }; declare const PROCEED: unique symbol; declare const SKIP: unique symbol; //#endregion export { IndexIdentifier, IndexOptimizer, IndexToCreate, OptimizeResult, PROCEED, PermutedIndexCandidate, RootIndexCandidate, SKIP }; //# sourceMappingURL=genalgo.d.cts.map