Skip to content

Commit

Permalink
Merge pull request #8650 from dolthub/macneale4/long-proc
Browse files Browse the repository at this point in the history
Enable larger statements for dolt_procedures
  • Loading branch information
macneale4 authored Dec 11, 2024
2 parents 1d72274 + 5fdb9bb commit a4a6fe1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
40 changes: 40 additions & 0 deletions go/libraries/doltcore/sqle/enginetest/dolt_procedure_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,4 +409,44 @@ end
},
},
},

{
Name: "create and call procedure which exceeds 1024 bytes",
SetUpScript: []string{
`CREATE PROCEDURE long_proc()
BEGIN
DECLARE long_text TEXT;
SET long_text = CONCAT(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ',
'Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ',
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris ',
'nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in ',
'reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ',
'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia ',
'deserunt mollit anim id est laborum.',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ',
'Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ',
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris ',
'nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in ',
'reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ',
'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia ',
'deserunt mollit anim id est laborum.',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ',
'Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ',
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris ',
'nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in ',
'reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ',
'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia ',
'deserunt mollit anim id est laborum.');
SELECT SHA2(long_text,256) AS checksum, LENGTH(long_text) AS length;
END
`,
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "call long_proc();",
Expected: []sql.Row{{"a702e99e5ee2dc03095bb2efd58e28330b6ea085d036249de82977a5c0dbb4be", 1335}},
},
},
},
}
17 changes: 16 additions & 1 deletion go/libraries/doltcore/sqle/procedures_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ import (
"time"

"github.com/dolthub/go-mysql-server/sql"
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
"github.com/dolthub/vitess/go/sqltypes"
"gopkg.in/src-d/go-errors.v1"

"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
"github.com/dolthub/dolt/go/libraries/doltcore/schema/typeinfo"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/index"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/sqlutil"
Expand Down Expand Up @@ -130,9 +133,21 @@ func ProceduresTableSqlSchema() sql.PrimaryKeySchema {

// The fixed dolt schema for the `dolt_procedures` table.
func ProceduresTableSchema() schema.Schema {
// Max len is 8K - big enough to be useful, but not too big to exceed max total row len of 64K.
t, err := gmstypes.CreateStringWithDefaults(sqltypes.VarChar, typeinfo.MaxVarcharLength/2)
if err != nil {
panic(err) // should never happen. All constants.
}
ti := typeinfo.CreateVarStringTypeFromSqlType(t)

stmtCol, err := schema.NewColumnWithTypeInfo(doltdb.ProceduresTableCreateStmtCol, schema.DoltProceduresCreateStmtTag, ti, false, "", false, "")
if err != nil {
panic(err) // should never happen.
}

colColl := schema.NewColCollection(
schema.NewColumn(doltdb.ProceduresTableNameCol, schema.DoltProceduresNameTag, types.StringKind, true, schema.NotNullConstraint{}),
schema.NewColumn(doltdb.ProceduresTableCreateStmtCol, schema.DoltProceduresCreateStmtTag, types.StringKind, false),
stmtCol,
schema.NewColumn(doltdb.ProceduresTableCreatedAtCol, schema.DoltProceduresCreatedAtTag, types.TimestampKind, false),
schema.NewColumn(doltdb.ProceduresTableModifiedAtCol, schema.DoltProceduresModifiedAtTag, types.TimestampKind, false),
schema.NewColumn(doltdb.ProceduresTableSqlModeCol, schema.DoltProceduresSqlModeTag, types.StringKind, false),
Expand Down

0 comments on commit a4a6fe1

Please sign in to comment.