Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
91a19b6
Preparing to add system tables
zachmu Jun 3, 2025
d9878e7
First pass at including system tables
zachmu Jun 3, 2025
7e0a77e
Moved function
zachmu Jun 3, 2025
9a784af
Bug fixes
zachmu Jun 4, 2025
f5a2475
Bug fixes
zachmu Jun 4, 2025
4ef057e
Tests of the dolt schema
zachmu Jun 4, 2025
80d7626
fixed tests for dolt_ tables addressable in any schema
zachmu Jun 4, 2025
16da658
new test
zachmu Jun 4, 2025
46d5b22
Added system table stubs to pg_class
zachmu Jun 5, 2025
73bf406
Back to basics: simpler tests for system tables in the pg_catalog tables
zachmu Jun 6, 2025
1e40450
focus test
zachmu Jun 10, 2025
e26f927
Merge branch 'main' into zachmu/pgcatalog_system_tables
zachmu Jun 10, 2025
61a1d01
bug fix for NOT IN
zachmu Jun 10, 2025
763d86f
Tests for not in
zachmu Jun 10, 2025
0d43239
Correctly return OIDs for system tables in pg_class table
zachmu Jun 10, 2025
37f9998
new test
zachmu Jun 10, 2025
9fc31ea
first pass at system tables in pg_attr
zachmu Jun 10, 2025
5ea6419
More tests
zachmu Jun 11, 2025
77f68c5
Unfocus test
zachmu Jun 11, 2025
bef4f32
Don't include dolt_ignore by default
zachmu Jun 11, 2025
dbd5703
Fixed test results
zachmu Jun 11, 2025
6a63f3d
Fixed tests
zachmu Jun 11, 2025
e0749fd
Fix tests
zachmu Jun 11, 2025
b298223
new dolt
zachmu Jun 11, 2025
89d5ca0
formatting
zachmu Jun 11, 2025
6a1b02a
Remove focus
zachmu Jun 11, 2025
855e5b9
fixed tests
zachmu Jun 11, 2025
24259b1
fixed tests
zachmu Jun 11, 2025
62e16e7
Fixed tests
zachmu Jun 11, 2025
54bf14b
Performance fix for regression testing
zachmu Jun 12, 2025
eedac17
Merge branch 'main' into zachmu/pgcatalog_system_tables
zachmu Jun 18, 2025
a9ccef9
New dolt
zachmu Jun 18, 2025
aa5298c
Fix compile errors
zachmu Jun 18, 2025
fef5e1f
fixed tests
zachmu Jun 18, 2025
d06e28e
skip failing dolt test
zachmu Jun 18, 2025
63c3d35
formatting
zachmu Jun 18, 2025
79065ca
new dolt
zachmu Jun 19, 2025
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
10 changes: 5 additions & 5 deletions core/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func getContextValues(ctx *sql.Context) (*contextValues, error) {
return cv, nil
}

// getRootFromContext returns the working session's root from the context, along with the session.
func getRootFromContext(ctx *sql.Context) (*dsess.DoltSession, *RootValue, error) {
// GetRootFromContext returns the working session's root from the context, along with the session.
func GetRootFromContext(ctx *sql.Context) (*dsess.DoltSession, *RootValue, error) {
return getRootFromContextForDatabase(ctx, "")
}

Expand Down Expand Up @@ -120,7 +120,7 @@ func SetPgCatalogCache(ctx *sql.Context, pgCatalogCache any) error {

// GetDoltTableFromContext returns the Dolt table from the context. Returns nil if no table was found.
func GetDoltTableFromContext(ctx *sql.Context, tableName doltdb.TableName) (*doltdb.Table, error) {
_, root, err := getRootFromContext(ctx)
_, root, err := GetRootFromContext(ctx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -220,7 +220,7 @@ func GetFunctionsCollectionFromContext(ctx *sql.Context) (*functions.Collection,
if err != nil {
return nil, err
}
_, root, err := getRootFromContext(ctx)
_, root, err := GetRootFromContext(ctx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -293,7 +293,7 @@ func GetTypesCollectionFromContext(ctx *sql.Context) (*typecollection.TypeCollec
return nil, err
}
if cv.types == nil {
_, root, err := getRootFromContext(ctx)
_, root, err := GetRootFromContext(ctx)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
// GetCurrentSchema returns the current schema used by the context. Defaults to "public" if the context does not specify
// a schema.
func GetCurrentSchema(ctx *sql.Context) (string, error) {
_, root, err := getRootFromContext(ctx)
_, root, err := GetRootFromContext(ctx)
if err != nil {
return "", nil
}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ require (
github.com/PuerkitoBio/goquery v1.8.1
github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a
github.com/cockroachdb/errors v1.7.5
github.com/dolthub/dolt/go v0.40.5-0.20250610173122-93301be37322
github.com/dolthub/dolt/go v0.40.5-0.20250619014715-a87c3da8efaf
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
github.com/dolthub/go-icu-regex v0.0.0-20250327004329-6799764f2dad
github.com/dolthub/go-mysql-server v0.20.1-0.20250609235012-75f15bbda63a
github.com/dolthub/go-mysql-server v0.20.1-0.20250618175653-7d22a78f4c71
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
github.com/dolthub/vitess v0.0.0-20250609213846-75541d7ef20a
github.com/dolthub/vitess v0.0.0-20250611225316-90a5898bfe26
github.com/fatih/color v1.13.0
github.com/goccy/go-json v0.10.2
github.com/gogo/protobuf v1.3.2
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5Xh
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dolthub/aws-sdk-go-ini-parser v0.0.0-20250305001723-2821c37f6c12 h1:IdqX7J8vi/Kn3T3Ee0VzqnLqwFmgA2hr8WZETPcQjfM=
github.com/dolthub/aws-sdk-go-ini-parser v0.0.0-20250305001723-2821c37f6c12/go.mod h1:rN7X8BHwkjPcfMQQ2QTAq/xM3leUSGLfb+1Js7Y6TVo=
github.com/dolthub/dolt/go v0.40.5-0.20250610173122-93301be37322 h1:a1RFFm9S7evoi52dDLYalO4dJ0ODZp0fpDzeGaRnMmU=
github.com/dolthub/dolt/go v0.40.5-0.20250610173122-93301be37322/go.mod h1:bCnd7kgVzluInixqje/NRPwykkjStWr8bLM+O8q6YB4=
github.com/dolthub/dolt/go v0.40.5-0.20250619014715-a87c3da8efaf h1:enouuGG0sJAlCN11sthy0ngFYN26vVvxDkgILI8VRRw=
github.com/dolthub/dolt/go v0.40.5-0.20250619014715-a87c3da8efaf/go.mod h1:iqXXu2G7HkrrV8G5v5a0I60HaxLeLSfjZLdP64ZepYM=
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d h1:gO9+wrmNHXukPNCO1tpfCcXIdMlW/qppbUStfLvqz/U=
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d/go.mod h1:L5RDYZbC9BBWmoU2+TjTekeqqhFXX5EqH9ln00O0stY=
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 h1:u3PMzfF8RkKd3lB9pZ2bfn0qEG+1Gms9599cr0REMww=
Expand All @@ -266,8 +266,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
github.com/dolthub/go-icu-regex v0.0.0-20250327004329-6799764f2dad h1:66ZPawHszNu37VPQckdhX1BPPVzREsGgNxQeefnlm3g=
github.com/dolthub/go-icu-regex v0.0.0-20250327004329-6799764f2dad/go.mod h1:ylU4XjUpsMcvl/BKeRRMXSH7e7WBrPXdSLvnRJYrxEA=
github.com/dolthub/go-mysql-server v0.20.1-0.20250609235012-75f15bbda63a h1:Q7obvACozcTOz11+L55dh1muPtNweIJdzNY5m0PLfDU=
github.com/dolthub/go-mysql-server v0.20.1-0.20250609235012-75f15bbda63a/go.mod h1:yVcBcDGOyYHmciKmQ20JZ+Mr12lOjSnzpmuBMZKPQGo=
github.com/dolthub/go-mysql-server v0.20.1-0.20250618175653-7d22a78f4c71 h1:KMg3/8YX0Jcs/AtghLroZ+RYp8FRo0Vvww9i2PmpUfw=
github.com/dolthub/go-mysql-server v0.20.1-0.20250618175653-7d22a78f4c71/go.mod h1:zuYoQ3keJHAvWUWMLzbP9anvR32b3sy1Fm8wB8ukNxQ=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=
Expand All @@ -276,8 +276,8 @@ github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 h1:bMGS25NWAGTE
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71/go.mod h1:2/2zjLQ/JOOSbbSboojeg+cAwcRV0fDLzIiWch/lhqI=
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 h1:JWkKRE4EHUcEVQCMRBej8DYxjYjRz/9MdF/NNQh0o70=
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216/go.mod h1:e/FIZVvT2IR53HBCAo41NjqgtEnjMJGKca3Y/dAmZaA=
github.com/dolthub/vitess v0.0.0-20250609213846-75541d7ef20a h1:DWQt6KSgrkZYuxzvGflImldau0a3IfINhEGQnFst/pw=
github.com/dolthub/vitess v0.0.0-20250609213846-75541d7ef20a/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
github.com/dolthub/vitess v0.0.0-20250611225316-90a5898bfe26 h1:9Npf0JYVCrwe9edTfYD/pjIncCePNDiu4j50xLcV334=
github.com/dolthub/vitess v0.0.0-20250611225316-90a5898bfe26/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
Expand Down
39 changes: 23 additions & 16 deletions server/ast/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,36 +361,43 @@ func nodeExpr(ctx *Context, node tree.Expr) (vitess.Expr, error) {
Expression: pgexprs.NewBinaryOperator(framework.Operator_BinaryNotEqual),
Children: vitess.Exprs{left, right},
}, nil
case tree.In:
case tree.In, tree.NotIn:
var innerExpression vitess.InjectedExpr
switch right := right.(type) {
case vitess.ValTuple:
return vitess.InjectedExpr{
innerExpression = vitess.InjectedExpr{
Expression: pgexprs.NewInTuple(),
Children: vitess.Exprs{left, right},
}, nil
}
case *vitess.Subquery:
return vitess.InjectedExpr{
innerExpression = vitess.InjectedExpr{
Expression: pgexprs.NewInSubquery(),
Children: vitess.Exprs{left, right},
}, nil
}
case vitess.InjectedExpr:
if _, ok := right.Expression.(*pgexprs.RecordExpr); ok {
return vitess.InjectedExpr{
innerExpression = vitess.InjectedExpr{
Expression: pgexprs.NewInTuple(),
Children: vitess.Exprs{left, vitess.ValTuple(right.Children)},
}, nil
}
}
}
return nil, errors.Errorf("right side of IN expression is not a tuple or subquery, got %T", right)
case tree.NotIn:
innerExpr := vitess.InjectedExpr{
Expression: pgexprs.NewInTuple(),
Children: vitess.Exprs{left, right},

if innerExpression.Expression == nil {
return nil, errors.Errorf("right side of IN expression is not a tuple or subquery, got %T", right)
}

switch node.Operator {
case tree.In:
return innerExpression, nil
case tree.NotIn:
return vitess.InjectedExpr{
Expression: pgexprs.NewNot(),
Children: vitess.Exprs{innerExpression},
}, nil
default:
return nil, errors.Errorf("unknown comparison operator used")
}
return vitess.InjectedExpr{
Expression: pgexprs.NewNot(),
Children: vitess.Exprs{innerExpr},
}, nil
case tree.Like:
operator = vitess.LikeStr
case tree.NotLike:
Expand Down
6 changes: 3 additions & 3 deletions server/expression/in_subquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
package expression

import (
"context"
"fmt"

"github.com/cockroachdb/errors"
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/expression"
"github.com/dolthub/go-mysql-server/sql/hash"
"github.com/dolthub/go-mysql-server/sql/plan"
"github.com/dolthub/go-mysql-server/sql/types"
vitess "github.com/dolthub/vitess/go/vt/sqlparser"
Expand All @@ -46,7 +46,7 @@ var _ sql.Expression = (*InSubquery)(nil)
var _ expression.BinaryExpression = (*InSubquery)(nil)

// nilKey is the hash of a row with a single nil value.
var nilKey, _ = sql.HashOf(context.TODO(), sql.NewRow(nil))
var nilKey, _ = hash.HashOf(nil, nil, sql.NewRow(nil))

// NewInSubquery returns a new *InSubquery.
func NewInSubquery() *InSubquery {
Expand Down Expand Up @@ -97,7 +97,7 @@ func (in *InSubquery) Eval(ctx *sql.Context, row sql.Row) (any, error) {

// TODO: it might be possible for the left value to hash to a different value than the right even though they pass
// an equality check. We need to perform a type conversion here to catch this case.
key, err := sql.HashOf(ctx, sql.NewRow(left))
key, err := hash.HashOf(ctx, nil, sql.NewRow(left))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion server/tables/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (d Database) GetTableInsensitive(ctx *sql.Context, tblName string) (sql.Tab
// exact search.
if tableMap, ok := handlers[d.db.Schema()]; ok {
if handler, ok := tableMap[tblName]; ok {
return NewVirtualTable(handler), true, nil
return NewVirtualTable(handler, d.db), true, nil
}
}
return nil, false, nil
Expand Down
14 changes: 14 additions & 0 deletions server/tables/pgcatalog/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@

package pgcatalog

import "os"

// PgCatalogName is a constant to the pg_catalog name.
const PgCatalogName = "pg_catalog"

// includeSystemTables is a flag to determine whether to include system tables in the pg_catalog tables.
var includeSystemTables = true

// Init initializes everything necessary for the pg_catalog tables.
func Init() {
InitIncludeSystemTables()
InitPgAggregate()
InitPgAm()
InitPgAmop()
Expand Down Expand Up @@ -159,3 +165,11 @@ func Init() {
InitPgUserMappings()
InitPgViews()
}

func InitIncludeSystemTables() {
if _, ok := os.LookupEnv("REGRESSION_TESTING"); ok {
// In CI regression tests, we exclude system tables to make them faster.
// None of them rely on the presence of system tables.
includeSystemTables = false
}
}
36 changes: 36 additions & 0 deletions server/tables/pgcatalog/pg_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ package pgcatalog
import (
"io"

"github.com/cockroachdb/errors"
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/resolve"
"github.com/dolthub/go-mysql-server/sql"

"github.com/dolthub/doltgresql/core"
"github.com/dolthub/doltgresql/core/id"
"github.com/dolthub/doltgresql/server/functions"
"github.com/dolthub/doltgresql/server/tables"
Expand Down Expand Up @@ -69,6 +73,38 @@ func (p PgAttributeHandler) RowIter(ctx *sql.Context) (sql.RowIter, error) {
if err != nil {
return nil, err
}

if includeSystemTables {
_, root, err := core.GetRootFromContext(ctx)
if err != nil {
return nil, err
}

systemTables, err := resolve.GetGeneratedSystemTables(ctx, root)
if err != nil {
return nil, err
}

db := ctx.GetCurrentDatabase()
for _, tblName := range systemTables {
tbl, err := core.GetSqlTableFromContext(ctx, db, tblName)
if err != nil {
// Some of the system tables exist conditionally when accessed, so just skip them in this case
if errors.Is(doltdb.ErrTableNotFound, err) {
continue
}
return nil, err
}

schema := tbl.Schema()
for i, col := range schema {
cols = append(cols, col)
colIdxs = append(colIdxs, i)
tableOIDs = append(tableOIDs, id.NewTable(tblName.Schema, tblName.Name).AsId())
}
}
}

pgCatalogCache.attributeCols = cols
pgCatalogCache.attributeColIdxs = colIdxs
pgCatalogCache.attributeTableOIDs = tableOIDs
Expand Down
3 changes: 2 additions & 1 deletion server/tables/pgcatalog/pg_catalog_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package pgcatalog

import (
"github.com/cockroachdb/errors"
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"

"github.com/dolthub/go-mysql-server/sql"

Expand Down Expand Up @@ -75,7 +76,7 @@ type pgCatalogCache struct {

// pg_tables
tables []sql.Table
tableSchemas []string
systemTables []doltdb.TableName
}

// newPgCatalogCache creates a new pgCatalogCache, with the query/process ID set to |pid|. The PID is important,
Expand Down
24 changes: 24 additions & 0 deletions server/tables/pgcatalog/pg_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import (
"fmt"
"io"

"github.com/dolthub/dolt/go/libraries/doltcore/sqle/resolve"
"github.com/dolthub/go-mysql-server/sql"

"github.com/dolthub/doltgresql/core"
"github.com/dolthub/doltgresql/core/id"
"github.com/dolthub/doltgresql/server/functions"
"github.com/dolthub/doltgresql/server/tables"
Expand Down Expand Up @@ -103,6 +105,28 @@ func (p PgClassHandler) RowIter(ctx *sql.Context) (sql.RowIter, error) {
if err != nil {
return nil, err
}

if includeSystemTables {
_, root, err := core.GetRootFromContext(ctx)
if err != nil {
return nil, err
}

systemTables, err := resolve.GetGeneratedSystemTables(ctx, root)
if err != nil {
return nil, err
}

for _, tblName := range systemTables {
classes = append(classes, pgClass{
oid: id.NewTable(tblName.Schema, tblName.Name).AsId(),
name: tblName.Name,
schemaOid: id.NewNamespace(tblName.Schema).AsId(),
kind: "r",
})
}
}

pgCatalogCache.pgClasses = classes
}

Expand Down
Loading