Skip to content

Commit f964380

Browse files
committed
Adding back the regclass_text overload, for performance reasons, since text->regclass->text conversion is very slow.
1 parent 11b329a commit f964380

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

server/functions/nextval.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,36 @@ import (
2424

2525
// initNextVal registers the functions to the catalog.
2626
func initNextVal() {
27+
framework.RegisterFunction(nextval_text)
2728
framework.RegisterFunction(nextval_regclass)
2829
}
2930

31+
// nextval_text represents the PostgreSQL function of the same name, taking the same parameters.
32+
//
33+
// TODO: Even though we can implicitly convert a text param to a regclass param, it's an expensive process
34+
// to convert it to a regclass, then convert the regclass back into the relation name, so we provide an overload
35+
// that takes a text param directly, in addition to the function form that takes a regclass. Once we can optimize
36+
// the regclass to text conversion, we can potentially remove this overload.
37+
var nextval_text = framework.Function1{
38+
Name: "nextval",
39+
Return: pgtypes.Int64,
40+
Parameters: [1]pgtypes.DoltgresType{pgtypes.Text},
41+
IsNonDeterministic: true,
42+
Strict: true,
43+
Callable: func(ctx *sql.Context, _ [2]pgtypes.DoltgresType, val any) (any, error) {
44+
schema, sequence, err := parseRelationName(ctx, val.(string))
45+
if err != nil {
46+
return nil, err
47+
}
48+
49+
collection, err := core.GetSequencesCollectionFromContext(ctx)
50+
if err != nil {
51+
return nil, err
52+
}
53+
return collection.NextVal(schema, sequence)
54+
},
55+
}
56+
3057
// nextval_regclass represents the PostgreSQL function of the same name, taking the same parameters.
3158
var nextval_regclass = framework.Function1{
3259
Name: "nextval",

server/types/text.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ func (b TextType) Convert(val any) (any, sql.ConvertInRange, error) {
106106

107107
// Equals implements the DoltgresType interface.
108108
func (b TextType) Equals(otherType sql.Type) bool {
109+
if _, ok := otherType.(TextType); !ok {
110+
return false
111+
}
112+
109113
if otherExtendedType, ok := otherType.(types.ExtendedType); ok {
110114
return bytes.Equal(MustSerializeType(b), MustSerializeType(otherExtendedType))
111115
}

0 commit comments

Comments
 (0)