Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .github/workflows/regression-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
cd testing/go/regression
mkdir -p out
cd tool
go test --timeout=20m ./... --count=1
go test --timeout=90m ./... --count=1
cp ../out/results.trackers ../out/results2.trackers

- name: Test main branch
Expand All @@ -66,7 +66,7 @@ jobs:
cd testing/go/regression
mkdir -p out
cd tool
go test --timeout=20m ./... --count=1
go test --timeout=90m ./... --count=1
cp ../out/results.trackers ../out/results1.trackers

- name: Check result trackers
Expand Down
35 changes: 35 additions & 0 deletions core/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/dolthub/doltgresql/core/functions"
"github.com/dolthub/doltgresql/core/sequences"
"github.com/dolthub/doltgresql/core/triggers"
"github.com/dolthub/doltgresql/core/typecollection"
)

Expand All @@ -33,6 +34,7 @@ type contextValues struct {
seqs *sequences.Collection
types *typecollection.TypeCollection
funcs *functions.Collection
trigs *triggers.Collection
pgCatalogCache any
}

Expand Down Expand Up @@ -244,6 +246,31 @@ func GetSequencesCollectionFromContext(ctx *sql.Context) (*sequences.Collection,
return cv.seqs, nil
}

// GetTriggersCollectionFromContext returns the triggers collection from the given context. Will always return a
// collection if no error is returned.
func GetTriggersCollectionFromContext(ctx *sql.Context) (*triggers.Collection, error) {
cv, err := getContextValues(ctx)
if err != nil {
return nil, err
}
_, root, err := getRootFromContext(ctx)
if err != nil {
return nil, err
}
if cv.trigs == nil {
cv.trigs, err = triggers.LoadTriggers(ctx, root)
if err != nil {
return nil, err
}
} else if cv.trigs.DiffersFrom(ctx, root) {
cv.trigs, err = triggers.LoadTriggers(ctx, root)
if err != nil {
return nil, err
}
}
return cv.trigs, nil
}

// GetTypesCollectionFromContext returns the given type collection from the context.
// Will always return a collection if no error is returned.
func GetTypesCollectionFromContext(ctx *sql.Context) (*typecollection.TypeCollection, error) {
Expand Down Expand Up @@ -296,6 +323,14 @@ func CloseContextRootFinalizer(ctx *sql.Context) error {
newRoot = retRoot.(*RootValue)
cv.funcs = nil
}
if cv.trigs != nil && cv.trigs.DiffersFrom(ctx, root) {
retRoot, err := cv.trigs.UpdateRoot(ctx, newRoot)
if err != nil {
return err
}
newRoot = retRoot.(*RootValue)
cv.trigs = nil
}
if cv.types != nil {
retRoot, err := cv.types.UpdateRoot(ctx, newRoot)
if err != nil {
Expand Down
18 changes: 14 additions & 4 deletions core/functions/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"maps"
"slices"
"strings"

"github.com/cockroachdb/errors"
Expand Down Expand Up @@ -268,6 +269,7 @@ func (pgf *Collection) Clone(ctx context.Context) *Collection {
return &Collection{
accessCache: maps.Clone(pgf.accessCache),
overloadCache: maps.Clone(pgf.overloadCache),
idCache: slices.Clone(pgf.idCache),
underlyingMap: pgf.underlyingMap,
mapHash: pgf.mapHash,
ns: pgf.ns,
Expand All @@ -286,7 +288,15 @@ func (pgf *Collection) DiffersFrom(ctx context.Context, root objinterface.RootVa
if err != nil {
return true
}
return !pgf.mapHash.Equal(hashOnGivenRoot)
if pgf.mapHash.Equal(hashOnGivenRoot) {
return false
}
// An empty map should match an uninitialized collection on the root
count, err := pgf.underlyingMap.Count()
if err == nil && count == 0 && hashOnGivenRoot.IsEmpty() {
return false
}
return true
}

// reloadCaches writes the underlying map's contents to the caches.
Expand Down Expand Up @@ -353,12 +363,12 @@ func (pgf *Collection) tableNameToID(schemaName string, formattedName string) id
return id.NewFunction(schemaName, functionName, typeIDs...)
}

// GetID implements the interface rootobject.RootObject.
// GetID implements the interface objinterface.RootObject.
func (function Function) GetID() objinterface.RootObjectID {
return objinterface.RootObjectID_Functions
}

// HashOf implements the interface rootobject.RootObject.
// HashOf implements the interface objinterface.RootObject.
func (function Function) HashOf(ctx context.Context) (hash.Hash, error) {
data, err := function.Serialize(ctx)
if err != nil {
Expand All @@ -367,7 +377,7 @@ func (function Function) HashOf(ctx context.Context) (hash.Hash, error) {
return hash.Of(data), nil
}

// Name implements the interface rootobject.RootObject.
// Name implements the interface objinterface.RootObject.
func (function Function) Name() doltdb.TableName {
return FunctionIDToTableName(function.ID)
}
Expand Down
2 changes: 2 additions & 0 deletions core/id/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ const (
NullSequence Sequence = ""
// NullTable is an empty, invalid ID. This is exactly equivalent to Null.
NullTable Table = ""
// NullTrigger is an empty, invalid ID. This is exactly equivalent to Null.
NullTrigger Trigger = ""
// NullType is an empty, invalid ID. This is exactly equivalent to Null.
NullType Type = ""
// NullView is an empty, invalid ID. This is exactly equivalent to Null.
Expand Down
32 changes: 32 additions & 0 deletions core/id/id_wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type Sequence Id
// Table is an Id wrapper for tables. This wrapper must not be returned to the client.
type Table Id

// Trigger is an Id wrapper for triggers. This wrapper must not be returned to the client.
type Trigger Id

// Type is an Id wrapper for types. This wrapper must not be returned to the client.
type Type Id

Expand Down Expand Up @@ -168,6 +171,14 @@ func NewTable(schemaName string, tableName string) Table {
return Table(NewId(Section_Table, schemaName, tableName))
}

// NewTrigger returns a new Trigger. This wrapper must not be returned to the client.
func NewTrigger(schemaName string, tableName string, triggerName string) Trigger {
if len(schemaName) == 0 && len(tableName) == 0 && len(triggerName) == 0 {
return NullTrigger
}
return Trigger(NewId(Section_Trigger, schemaName, tableName, triggerName))
}

// NewType returns a new Type. This wrapper must not be returned to the client.
func NewType(schemaName string, typeName string) Type {
if len(schemaName) == 0 && len(typeName) == 0 {
Expand Down Expand Up @@ -330,6 +341,21 @@ func (id Table) TableName() string {
return Id(id).Segment(1)
}

// SchemaName returns the schema name of the trigger.
func (id Trigger) SchemaName() string {
return Id(id).Segment(0)
}

// TableName returns the name of the table that the trigger belongs to.
func (id Trigger) TableName() string {
return Id(id).Segment(1)
}

// TriggerName returns the trigger's name.
func (id Trigger) TriggerName() string {
return Id(id).Segment(2)
}

// SchemaName returns the schema name of the type.
func (id Type) SchemaName() string {
return Id(id).Segment(0)
Expand Down Expand Up @@ -389,6 +415,9 @@ func (id Sequence) IsValid() bool { return Id(id).IsValid() }
// IsValid returns whether the ID is valid.
func (id Table) IsValid() bool { return Id(id).IsValid() }

// IsValid returns whether the ID is valid.
func (id Trigger) IsValid() bool { return Id(id).IsValid() }

// IsValid returns whether the ID is valid.
func (id Type) IsValid() bool { return Id(id).IsValid() }

Expand Down Expand Up @@ -434,6 +463,9 @@ func (id Sequence) AsId() Id { return Id(id) }
// AsId returns the unwrapped ID.
func (id Table) AsId() Id { return Id(id) }

// AsId returns the unwrapped ID.
func (id Trigger) AsId() Id { return Id(id) }

// AsId returns the unwrapped ID.
func (id Type) AsId() Id { return Id(id) }

Expand Down
29 changes: 29 additions & 0 deletions core/id/table.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2025 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package id

import (
"github.com/cockroachdb/errors"
"github.com/dolthub/go-mysql-server/sql"
)

// GetFromTable returns the id from the table.
func GetFromTable(ctx *sql.Context, tbl sql.Table) (Table, bool, error) {
schTbl, ok := tbl.(sql.DatabaseSchemaTable)
if !ok {
return NullTable, false, errors.Newf(`table "%s" does not specify a schema`, tbl.Name())
}
return NewTable(schTbl.DatabaseSchema().SchemaName(), schTbl.Name()), true, nil
}
2 changes: 2 additions & 0 deletions core/rootobject/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/dolthub/doltgresql/core/id"
"github.com/dolthub/doltgresql/core/rootobject/objinterface"
"github.com/dolthub/doltgresql/core/sequences"
"github.com/dolthub/doltgresql/core/triggers"
"github.com/dolthub/doltgresql/core/typecollection"
)

Expand All @@ -36,6 +37,7 @@ var (
&sequences.Collection{},
&typecollection.TypeCollection{},
&functions.Collection{},
&triggers.Collection{},
}
)

Expand Down
1 change: 1 addition & 0 deletions core/rootobject/objinterface/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
RootObjectID_Sequences
RootObjectID_Types
RootObjectID_Functions
RootObjectID_Triggers
)

// Collection is a collection of root objects.
Expand Down
Loading