@@ -17,8 +17,8 @@ package function
1717import (
1818 "fmt"
1919 "sync"
20- "time"
2120
21+ "github.com/dolthub/go-mysql-server/sql/variables"
2222 "github.com/dolthub/vitess/go/sqltypes"
2323 "github.com/dolthub/vitess/go/vt/proto/query"
2424 "github.com/google/uuid"
@@ -31,7 +31,6 @@ import (
3131var (
3232 uuidShortMu sync.Mutex
3333 uuidShortCounter uint64
34- uuidShortStartup = uint64 (time .Now ().Unix ())
3534)
3635
3736// UUID()
@@ -563,24 +562,27 @@ func NewUUIDShortFunc() sql.Expression {
563562 return & UUIDShortFunc {}
564563}
565564
566- // Description implements sql.FunctionExpression
567- func (u UUIDShortFunc ) Description () string {
565+ // Description returns a human-readable description of the UUID_SHORT function.
566+ func (u * UUIDShortFunc ) Description () string {
568567 return "returns a short universal identifier as a 64-bit unsigned integer."
569568}
570569
571- func (u UUIDShortFunc ) String () string {
570+ // String returns a string representation of the UUID_SHORT function call.
571+ func (u * UUIDShortFunc ) String () string {
572572 return "UUID_SHORT()"
573573}
574574
575- func (u UUIDShortFunc ) Type () sql.Type {
575+ // Type returns the data type of the UUID_SHORT function result (Uint64).
576+ func (u * UUIDShortFunc ) Type () sql.Type {
576577 return types .Uint64
577578}
578579
579580// CollationCoercibility implements the interface sql.CollationCoercible.
580- func (UUIDShortFunc ) CollationCoercibility (ctx * sql.Context ) (collation sql.CollationID , coercibility byte ) {
581+ func (u * UUIDShortFunc ) CollationCoercibility (ctx * sql.Context ) (collation sql.CollationID , coercibility byte ) {
581582 return sql .Collation_binary , 5
582583}
583584
585+ // Eval generates a 64-bit UUID_SHORT value using server_id, startup time, and counter.
584586func (u * UUIDShortFunc ) Eval (ctx * sql.Context , row sql.Row ) (interface {}, error ) {
585587 uuidShortMu .Lock ()
586588 defer uuidShortMu .Unlock ()
@@ -595,37 +597,40 @@ func (u *UUIDShortFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error)
595597 }
596598
597599 // Construct the UUID_SHORT value according to MySQL specification:
598- result := ((serverID & 255 ) << 56 ) + (uuidShortStartup << 24 ) + uuidShortCounter
599-
600+ result := ((serverID & 255 ) << 56 ) + (uint64 (variables .ServerStartUpTime .Unix ()) << 24 ) + uuidShortCounter
600601 return result , nil
601602}
602603
603- func (u UUIDShortFunc ) WithChildren (children ... sql.Expression ) (sql.Expression , error ) {
604+ // WithChildren returns a new UUID_SHORT function with the given children (must be empty).
605+ func (u * UUIDShortFunc ) WithChildren (children ... sql.Expression ) (sql.Expression , error ) {
604606 if len (children ) != 0 {
605607 return nil , sql .ErrInvalidChildrenNumber .New (u , len (children ), 0 )
606608 }
607609
608610 return & UUIDShortFunc {}, nil
609611}
610612
611- func (u UUIDShortFunc ) FunctionName () string {
613+ // FunctionName returns the name of the UUID_SHORT function.
614+ func (u * UUIDShortFunc ) FunctionName () string {
612615 return "UUID_SHORT"
613616}
614617
615- func (u UUIDShortFunc ) Resolved () bool {
618+ // Resolved returns true since UUID_SHORT has no dependencies to resolve.
619+ func (u * UUIDShortFunc ) Resolved () bool {
616620 return true
617621}
618622
619623// Children returns the children expressions of this expression.
620- func (u UUIDShortFunc ) Children () []sql.Expression {
624+ func (u * UUIDShortFunc ) Children () []sql.Expression {
621625 return nil
622626}
623627
624- // IsNullable returns whether the expression can be null .
625- func (u UUIDShortFunc ) IsNullable () bool {
628+ // IsNullable returns false since UUID_SHORT always returns a value .
629+ func (u * UUIDShortFunc ) IsNullable () bool {
626630 return false
627631}
628632
629- func (u UUIDShortFunc ) IsNonDeterministic () bool {
633+ // IsNonDeterministic returns true since UUID_SHORT generates different values on each call.
634+ func (u * UUIDShortFunc ) IsNonDeterministic () bool {
630635 return true
631636}
0 commit comments