Skip to content

Commit c257644

Browse files
authored
Merge pull request #2093 from dolthub/zachmu/index-rewrite
remove doltgres index implementation, various bug fixes
2 parents 38bde13 + 0bc839f commit c257644

32 files changed

Lines changed: 526 additions & 1052 deletions

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ require (
66
github.com/PuerkitoBio/goquery v1.8.1
77
github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a
88
github.com/cockroachdb/errors v1.7.5
9-
github.com/dolthub/dolt/go v0.40.5-0.20251209113019-d956afb08a95
9+
github.com/dolthub/dolt/go v0.40.5-0.20251211214546-0b9999455622
1010
github.com/dolthub/eventsapi_schema v0.0.0-20250915094920-eadfd39051ca
1111
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
12-
github.com/dolthub/go-mysql-server v0.20.1-0.20251202232204-0b1008f3c7d9
12+
github.com/dolthub/go-mysql-server v0.20.1-0.20251211205836-45695e02d2b6
1313
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
14-
github.com/dolthub/vitess v0.0.0-20251124192614-8039a9881a64
14+
github.com/dolthub/vitess v0.0.0-20251210200925-1d33d416d162
1515
github.com/fatih/color v1.13.0
1616
github.com/goccy/go-json v0.10.2
1717
github.com/gogo/protobuf v1.3.2

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ github.com/dolthub/aws-sdk-go-ini-parser v0.0.0-20250305001723-2821c37f6c12 h1:I
228228
github.com/dolthub/aws-sdk-go-ini-parser v0.0.0-20250305001723-2821c37f6c12/go.mod h1:rN7X8BHwkjPcfMQQ2QTAq/xM3leUSGLfb+1Js7Y6TVo=
229229
github.com/dolthub/dolt-mcp v0.2.2 h1:bpROmam74n95uU4EA3BpOIVlTDT0pzeFMBwe/YRq2mI=
230230
github.com/dolthub/dolt-mcp v0.2.2/go.mod h1:S++DJ4QWTAXq+0TNzFa7Oq3IhoT456DJHwAINFAHgDQ=
231-
github.com/dolthub/dolt/go v0.40.5-0.20251209113019-d956afb08a95 h1:Mw0uCDss/B9cfqCQ7rGq6pv6hSg3N0BToqaS59wW9z0=
232-
github.com/dolthub/dolt/go v0.40.5-0.20251209113019-d956afb08a95/go.mod h1:m1iGy0r1OfkYJ0JibA6yIuz2lKhmZauzN4rIlAyMGog=
231+
github.com/dolthub/dolt/go v0.40.5-0.20251211214546-0b9999455622 h1:M0FRziRmHiiv4osP2f5AR+nhY1KnIiclax4gXb3hlGg=
232+
github.com/dolthub/dolt/go v0.40.5-0.20251211214546-0b9999455622/go.mod h1:+g40yZ9gyg0JIgaiwCpfjAG9OAbp35DMseO9W7OISQg=
233233
github.com/dolthub/eventsapi_schema v0.0.0-20250915094920-eadfd39051ca h1:BGFz/0OlKIuC6qHIZQbvPapFvdAJkeEyGXWVgL5clmE=
234234
github.com/dolthub/eventsapi_schema v0.0.0-20250915094920-eadfd39051ca/go.mod h1:CoDLfgPqHyBtth0Cp+fi/CmC4R81zJNX4wPjShdZ+Bw=
235235
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 h1:u3PMzfF8RkKd3lB9pZ2bfn0qEG+1Gms9599cr0REMww=
@@ -238,8 +238,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
238238
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
239239
github.com/dolthub/go-icu-regex v0.0.0-20250916051405-78a38d478790 h1:zxMsH7RLiG+dlZ/y0LgJHTV26XoiSJcuWq+em6t6VVc=
240240
github.com/dolthub/go-icu-regex v0.0.0-20250916051405-78a38d478790/go.mod h1:F3cnm+vMRK1HaU6+rNqQrOCyR03HHhR1GWG2gnPOqaE=
241-
github.com/dolthub/go-mysql-server v0.20.1-0.20251202232204-0b1008f3c7d9 h1:jw7LJ/UUyH6ptW5c6pPeKMMquOtZpwyjyQgMCCB4FIA=
242-
github.com/dolthub/go-mysql-server v0.20.1-0.20251202232204-0b1008f3c7d9/go.mod h1:pD0T+xZWBDO5yxHAY9FUqArKvhvw6KYqxRmEk3NfQNw=
241+
github.com/dolthub/go-mysql-server v0.20.1-0.20251211205836-45695e02d2b6 h1:pLvSf/YvXYyCaWFso9QVWMaRSR4/+hIPnx5QtEd78p8=
242+
github.com/dolthub/go-mysql-server v0.20.1-0.20251211205836-45695e02d2b6/go.mod h1:NjewWKoa5bVSLdKwL7fg7eAfrcIxDybWUKoWEHWRTw4=
243243
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
244244
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
245245
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=
@@ -250,8 +250,8 @@ github.com/dolthub/pg_query_go/v6 v6.0.0-20250702135351-29eb6bfc4ea6 h1:UEX3FGaC
250250
github.com/dolthub/pg_query_go/v6 v6.0.0-20250702135351-29eb6bfc4ea6/go.mod h1:nvTHIuoud6e1SfrUaFwHqT0i4b5Nr+1rPWVds3B5+50=
251251
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 h1:JWkKRE4EHUcEVQCMRBej8DYxjYjRz/9MdF/NNQh0o70=
252252
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216/go.mod h1:e/FIZVvT2IR53HBCAo41NjqgtEnjMJGKca3Y/dAmZaA=
253-
github.com/dolthub/vitess v0.0.0-20251124192614-8039a9881a64 h1:E3IfAYxrZ+dXgBHXN9L1ucotg3J8YDCeDr47u78tUI4=
254-
github.com/dolthub/vitess v0.0.0-20251124192614-8039a9881a64/go.mod h1:FLWqdXsAeeBQyFwDjmBVu0GnbjI2MKeRf3tRVdJEKlI=
253+
github.com/dolthub/vitess v0.0.0-20251210200925-1d33d416d162 h1:6RW2VpUs/cUFdvk4mXSmJfQZLs9wJABVjke3CHGJBcs=
254+
github.com/dolthub/vitess v0.0.0-20251210200925-1d33d416d162/go.mod h1:FLWqdXsAeeBQyFwDjmBVu0GnbjI2MKeRf3tRVdJEKlI=
255255
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
256256
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
257257
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=

postgres/parser/parser/lexer.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (l *lexer) Lex(lval *sqlSymType) int {
9595
*lval = l.tokens[l.lastPos]
9696

9797
switch lval.id {
98-
case NOT, WITH, AS, GENERATED:
98+
case NOT, WITH, AS, GENERATED, BLOCK_COMMENT:
9999
nextID := int32(0)
100100
if l.lastPos+1 < len(l.tokens) {
101101
nextID = l.tokens[l.lastPos+1].id
@@ -123,6 +123,13 @@ func (l *lexer) Lex(lval *sqlSymType) int {
123123
case TIME, ORDINALITY:
124124
lval.id = WITH_LA
125125
}
126+
case BLOCK_COMMENT:
127+
// for all block comments, skip returning them unless followed by the HINT token
128+
switch nextID {
129+
case HINT:
130+
default:
131+
return l.Lex(lval)
132+
}
126133
}
127134
}
128135

postgres/parser/parser/scan.go

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,16 @@ func (s *scanner) scan(lval *sqlSymType) {
108108
lval.pos = int32(s.pos)
109109
lval.str = "EOF"
110110

111-
if _, ok := s.skipWhitespace(lval, true); !ok {
112-
return
111+
for {
112+
if comment, _, ok := s.skipWhitespace(lval, true); !ok {
113+
return
114+
} else if comment != "" {
115+
lval.str = comment
116+
lval.id = BLOCK_COMMENT
117+
return
118+
} else {
119+
break
120+
}
113121
}
114122

115123
ch := s.next()
@@ -352,7 +360,7 @@ func (s *scanner) scan(lval *sqlSymType) {
352360
s.pos++
353361
lval.id = CONTAINS
354362
return
355-
case '@': //@@
363+
case '@': // @@
356364
s.pos++
357365
lval.id = TEXTSEARCHMATCH
358366
}
@@ -439,7 +447,9 @@ func (s *scanner) next() int {
439447
return ch
440448
}
441449

442-
func (s *scanner) skipWhitespace(lval *sqlSymType, allowComments bool) (newline, ok bool) {
450+
// skipWhitespace skips over whitespace characters (space, tab, newline, etc) and comments. Multiple consecutive
451+
// block comments and whitespace will be concatenated together into the final return value.
452+
func (s *scanner) skipWhitespace(lval *sqlSymType, allowComments bool) (blockComment string, newline, ok bool) {
443453
newline = false
444454
for {
445455
ch := s.peek()
@@ -453,37 +463,55 @@ func (s *scanner) skipWhitespace(lval *sqlSymType, allowComments bool) (newline,
453463
continue
454464
}
455465
if allowComments {
456-
if present, cok := s.scanComment(lval); !cok {
457-
return false, false
466+
if cmt, present, cok := s.scanComment(lval); !cok {
467+
return "", false, false
458468
} else if present {
469+
if len(blockComment) > 0 {
470+
blockComment += " "
471+
}
472+
blockComment += cmt
459473
continue
460474
}
461475
}
462476
break
463477
}
464-
return newline, true
478+
return blockComment, newline, true
465479
}
466480

467-
func (s *scanner) scanComment(lval *sqlSymType) (present, ok bool) {
481+
// scanComment scans for a comment starting at the current position.
482+
// For block-style comments, returns the comment string scanned.
483+
// For line-style comments, returns an empty string.
484+
// In either case, also returns whether a comment was present, and whether scanning succeeded.
485+
func (s *scanner) scanComment(lval *sqlSymType) (comment string, present, ok bool) {
468486
start := s.pos
469487
ch := s.peek()
470488

471489
if ch == '/' {
490+
sb := strings.Builder{}
491+
sb.WriteRune('/')
492+
472493
s.pos++
473494
if s.peek() != '*' {
474495
s.pos--
475-
return false, true
496+
return "", false, true
476497
}
498+
sb.WriteRune('*')
499+
477500
s.pos++
478501
depth := 1
479502
for {
480-
switch s.next() {
503+
next := s.next()
504+
sb.WriteRune(rune(next))
505+
506+
switch next {
481507
case '*':
482508
if s.peek() == '/' {
483509
s.pos++
484510
depth--
511+
sb.WriteRune(rune('/'))
512+
485513
if depth == 0 {
486-
return true, true
514+
return sb.String(), true, true
487515
}
488516
continue
489517
}
@@ -492,14 +520,15 @@ func (s *scanner) scanComment(lval *sqlSymType) (present, ok bool) {
492520
if s.peek() == '*' {
493521
s.pos++
494522
depth++
523+
sb.WriteRune(rune('*'))
495524
continue
496525
}
497526

498527
case eof:
499528
lval.id = ERROR
500529
lval.pos = int32(start)
501530
lval.str = "unterminated comment"
502-
return false, false
531+
return "", false, false
503532
}
504533
}
505534
}
@@ -508,17 +537,17 @@ func (s *scanner) scanComment(lval *sqlSymType) (present, ok bool) {
508537
s.pos++
509538
if s.peek() != '-' {
510539
s.pos--
511-
return false, true
540+
return "", false, true
512541
}
513542
for {
514543
switch s.next() {
515544
case eof, '\n':
516-
return true, true
545+
return "", true, true
517546
}
518547
}
519548
}
520549

521-
return false, true
550+
return "", false, true
522551
}
523552

524553
func (s *scanner) scanIdent(lval *sqlSymType) {
@@ -535,7 +564,7 @@ func (s *scanner) scanIdent(lval *sqlSymType) {
535564
// of whether the string is only ASCII or only ASCII lowercase for later.
536565
for {
537566
ch := s.peek()
538-
//fmt.Println(ch, ch >= utf8.RuneSelf, ch >= 'A' && ch <= 'Z')
567+
// fmt.Println(ch, ch >= utf8.RuneSelf, ch >= 'A' && ch <= 'Z')
539568

540569
if ch >= utf8.RuneSelf {
541570
isASCII = false
@@ -549,7 +578,7 @@ func (s *scanner) scanIdent(lval *sqlSymType) {
549578

550579
s.pos++
551580
}
552-
//fmt.Println("parsed: ", s.in[start:s.pos], isASCII, isLower)
581+
// fmt.Println("parsed: ", s.in[start:s.pos], isASCII, isLower)
553582

554583
if isLower {
555584
// Already lowercased - nothing to do.
@@ -730,7 +759,7 @@ outer:
730759
b := s.next()
731760
switch b {
732761
case ch:
733-
newline, ok := s.skipWhitespace(lval, false)
762+
_, newline, ok := s.skipWhitespace(lval, false)
734763
if !ok {
735764
return false
736765
}
@@ -783,7 +812,7 @@ outer:
783812
b := s.next()
784813
switch b {
785814
case ch:
786-
newline, ok := s.skipWhitespace(lval, false)
815+
_, newline, ok := s.skipWhitespace(lval, false)
787816
if !ok {
788817
return false
789818
}
@@ -832,7 +861,7 @@ outer:
832861
continue
833862
}
834863

835-
newline, ok := s.skipWhitespace(lval, false)
864+
_, newline, ok := s.skipWhitespace(lval, false)
836865
if !ok {
837866
return false
838867
}

postgres/parser/parser/sql.y

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ func (u *sqlSymUnion) vacuumTableAndColsList() tree.VacuumTableAndColsList {
719719
%token <str> CACHE CHAIN CALL CALLED CANCEL CANCELQUERY CANONICAL CASCADE CASCADED CASE CAST CATEGORY CBRT
720720
%token <str> CHANGEFEED CHAR CHARACTER CHARACTERISTICS CHECK CHECK_OPTION CLASS CLOSE
721721
%token <str> CLUSTER COALESCE COLLATABLE COLLATE COLLATION COLLATION_VERSION COLUMN COLUMNS COMBINEFUNC COMMENT COMMENTS
722+
%token <str> BLOCK_COMMENT HINT
722723
%token <str> COMMIT COMMITTED COMPACT COMPLETE COMPRESSION CONCAT CONCURRENTLY CONFIGURATION CONFIGURATIONS CONFIGURE
723724
%token <str> CONFLICT CONNECT CONNECTION CONSTRAINT CONSTRAINTS CONTAINS CONTROLCHANGEFEED
724725
%token <str> CONTROLJOB CONVERSION CONVERT COPY COST CREATE CREATEDB CREATELOGIN CREATEROLE
@@ -1382,6 +1383,8 @@ func (u *sqlSymUnion) vacuumTableAndColsList() tree.VacuumTableAndColsList {
13821383
%type <tree.Persistence> opt_temp opt_persistence_temp_table opt_persistence_sequence
13831384
%type <bool> role_or_group_or_user role_or_user opt_with_grant_option opt_grant_option_for
13841385

1386+
%type <str> opt_join_hint_comment
1387+
13851388
%type <tree.Expr> cron_expr opt_description sconst_or_placeholder
13861389
%type <*tree.FullBackupClause> opt_full_backup_clause
13871390
%type <tree.ScheduleState> schedule_state
@@ -10641,50 +10644,62 @@ empty_select:
1064110644
// [ OFFSET <expr> [ ROW | ROWS ] ]
1064210645
// %SeeAlso: WEBDOCS/select-clause.html
1064310646
simple_select_clause:
10644-
SELECT opt_all_clause target_list
10647+
SELECT opt_join_hint_comment opt_all_clause target_list
1064510648
from_clause opt_where_clause
1064610649
group_clause having_clause window_clause
1064710650
{
1064810651
$$.val = &tree.SelectClause{
10649-
Exprs: $3.selExprs(),
10650-
From: $4.from(),
10651-
Where: tree.NewWhere(tree.AstWhere, $5.expr()),
10652-
GroupBy: $6.groupBy(),
10653-
Having: tree.NewWhere(tree.AstHaving, $7.expr()),
10654-
Window: $8.window(),
10652+
BlockComment: $2,
10653+
Exprs: $4.selExprs(),
10654+
From: $5.from(),
10655+
Where: tree.NewWhere(tree.AstWhere, $6.expr()),
10656+
GroupBy: $7.groupBy(),
10657+
Having: tree.NewWhere(tree.AstHaving, $8.expr()),
10658+
Window: $9.window(),
1065510659
}
1065610660
}
10657-
| SELECT distinct_clause target_list
10661+
| SELECT opt_join_hint_comment distinct_clause target_list
1065810662
from_clause opt_where_clause
1065910663
group_clause having_clause window_clause
1066010664
{
1066110665
$$.val = &tree.SelectClause{
10662-
Distinct: $2.bool(),
10663-
Exprs: $3.selExprs(),
10664-
From: $4.from(),
10665-
Where: tree.NewWhere(tree.AstWhere, $5.expr()),
10666-
GroupBy: $6.groupBy(),
10667-
Having: tree.NewWhere(tree.AstHaving, $7.expr()),
10668-
Window: $8.window(),
10666+
BlockComment: $2,
10667+
Distinct: $3.bool(),
10668+
Exprs: $4.selExprs(),
10669+
From: $5.from(),
10670+
Where: tree.NewWhere(tree.AstWhere, $6.expr()),
10671+
GroupBy: $7.groupBy(),
10672+
Having: tree.NewWhere(tree.AstHaving, $8.expr()),
10673+
Window: $9.window(),
1066910674
}
1067010675
}
10671-
| SELECT distinct_on_clause target_list
10676+
| SELECT opt_join_hint_comment distinct_on_clause target_list
1067210677
from_clause opt_where_clause
1067310678
group_clause having_clause window_clause
1067410679
{
1067510680
$$.val = &tree.SelectClause{
10681+
BlockComment: $2,
1067610682
Distinct: true,
10677-
DistinctOn: $2.distinctOn(),
10678-
Exprs: $3.selExprs(),
10679-
From: $4.from(),
10680-
Where: tree.NewWhere(tree.AstWhere, $5.expr()),
10681-
GroupBy: $6.groupBy(),
10682-
Having: tree.NewWhere(tree.AstHaving, $7.expr()),
10683-
Window: $8.window(),
10683+
DistinctOn: $3.distinctOn(),
10684+
Exprs: $4.selExprs(),
10685+
From: $5.from(),
10686+
Where: tree.NewWhere(tree.AstWhere, $6.expr()),
10687+
GroupBy: $7.groupBy(),
10688+
Having: tree.NewWhere(tree.AstHaving, $8.expr()),
10689+
Window: $9.window(),
1068410690
}
1068510691
}
1068610692
| SELECT error // SHOW HELP: SELECT
1068710693

10694+
opt_join_hint_comment:
10695+
{
10696+
// empty
10697+
}
10698+
| BLOCK_COMMENT HINT
10699+
{
10700+
$$ = $1
10701+
}
10702+
1068810703
set_operation:
1068910704
select_clause UNION all_or_distinct select_clause
1069010705
{
@@ -15113,6 +15128,7 @@ col_name_keyword:
1511315128
| GEOMETRY
1511415129
| GREATEST
1511515130
| GROUPING
15131+
| HINT
1511615132
| IF
1511715133
| IFERROR
1511815134
| IFNULL

postgres/parser/sem/tree/select.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,16 @@ func (node *ParenSelect) Format(ctx *FmtCtx) {
9191

9292
// SelectClause represents a SELECT statement.
9393
type SelectClause struct {
94-
Distinct bool
95-
DistinctOn DistinctOn
96-
Exprs SelectExprs
97-
From From
98-
Where *Where
99-
GroupBy GroupBy
100-
Having *Where
101-
Window Window
102-
TableSelect bool
94+
Distinct bool
95+
DistinctOn DistinctOn
96+
Exprs SelectExprs
97+
From From
98+
Where *Where
99+
GroupBy GroupBy
100+
Having *Where
101+
Window Window
102+
TableSelect bool
103+
BlockComment string
103104
}
104105

105106
// Format implements the NodeFormatter interface.

0 commit comments

Comments
 (0)