Skip to content

Commit a7097ea

Browse files
committed
fix: empty page crash, reindex estimate, HOT detection, row count display
1 parent 7b38a79 commit a7097ea

File tree

5 files changed

+290
-66
lines changed

5 files changed

+290
-66
lines changed

internal/inspector/heap.go

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -423,24 +423,34 @@ func (i *Inspector) ExecuteDemoUpdate(ctx context.Context, table, pk, column, ne
423423
samePage := loc.Page == newLoc.Page
424424
isHot := samePage && hasFlag(after.InfoMask, "HEAP_HOT_UPDATED")
425425

426+
// Check if the column is actually indexed
427+
isColumnIndexed := false
428+
for _, ic := range info.IndexedColumns {
429+
if ic == column {
430+
isColumnIndexed = true
431+
break
432+
}
433+
}
434+
426435
updateType := "regular"
427436
if isHot {
428437
updateType = "hot"
429438
}
430439

431-
explanation := buildExplanation(isHot, samePage, loc, newLoc, column)
440+
explanation := buildExplanation(isHot, samePage, isColumnIndexed, loc, newLoc, column)
432441

433442
return &DemoUpdateResult{
434-
Success: true,
435-
UpdateType: updateType,
436-
Column: column,
437-
OldValue: oldVal,
438-
NewValue: newVal,
439-
Before: before,
440-
After: after,
441-
NewTuple: newState,
442-
SamePage: samePage,
443-
Explanation: explanation,
443+
Success: true,
444+
UpdateType: updateType,
445+
Column: column,
446+
IsColumnIndexed: isColumnIndexed,
447+
OldValue: oldVal,
448+
NewValue: newVal,
449+
Before: before,
450+
After: after,
451+
NewTuple: newState,
452+
SamePage: samePage,
453+
Explanation: explanation,
444454
}, nil
445455
}
446456

@@ -620,20 +630,26 @@ func tupleState(loc *RowLocation, t *HeapTuple) DemoTupleState {
620630
}
621631
}
622632

623-
func buildExplanation(isHot, samePage bool, before, after *RowLocation, col string) string {
633+
func buildExplanation(isHot, samePage, isColumnIndexed bool, before, after *RowLocation, col string) string {
624634
if isHot {
635+
if isColumnIndexed {
636+
// This shouldn't happen - HOT with indexed column change
637+
return fmt.Sprintf(
638+
"🔥 HOT UPDATE (unexpected): column '%s' IS indexed but PostgreSQL used HOT. Value may be bitwise identical, or check if index exists. Page %d, lp %d→%d.",
639+
col, before.Page, before.Item, after.Item)
640+
}
625641
return fmt.Sprintf(
626-
"🔥 HOT UPDATE: new tuple on same page (%d). Old tuple at lp=%d has HEAP_HOT_UPDATED and points to lp=%d. Index not updated since only '%s' changed.",
627-
before.Page, before.Item, after.Item, col)
642+
"🔥 HOT UPDATE: column '%s' is not indexed, so no index update needed. New tuple on same page (%d), lp %d→%d.",
643+
col, before.Page, before.Item, after.Item)
628644
}
629645
if samePage {
630646
return fmt.Sprintf(
631-
"📦 REGULAR UPDATE (same page %d): indexed column '%s' modified, index updated.",
632-
before.Page, col)
647+
"📦 REGULAR UPDATE (same page %d): column '%s' is indexed, index was updated. lp %d→%d.",
648+
before.Page, col, before.Item, after.Item)
633649
}
634650
return fmt.Sprintf(
635-
"📦 REGULAR UPDATE: tuple moved from page %d to %d. Index updated.",
636-
before.Page, after.Page)
651+
"📦 REGULAR UPDATE: tuple moved from page %d (lp=%d) to page %d (lp=%d). Index updated.",
652+
before.Page, before.Item, after.Page, after.Item)
637653
}
638654

639655
func lpFlagsStr(f int) string {

internal/inspector/types.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,18 @@ type DemoTupleState struct {
9393
}
9494

9595
type DemoUpdateResult struct {
96-
Success bool `json:"success"`
97-
Error string `json:"error,omitempty"`
98-
UpdateType string `json:"updateType"`
99-
Column string `json:"column"`
100-
OldValue string `json:"oldValue"`
101-
NewValue string `json:"newValue"`
102-
Before DemoTupleState `json:"before"`
103-
After DemoTupleState `json:"after"`
104-
NewTuple *DemoTupleState `json:"newTuple"`
105-
SamePage bool `json:"samePage"`
106-
Explanation string `json:"explanation"`
96+
Success bool `json:"success"`
97+
Error string `json:"error,omitempty"`
98+
UpdateType string `json:"updateType"`
99+
Column string `json:"column"`
100+
IsColumnIndexed bool `json:"isColumnIndexed"`
101+
OldValue string `json:"oldValue"`
102+
NewValue string `json:"newValue"`
103+
Before DemoTupleState `json:"before"`
104+
After DemoTupleState `json:"after"`
105+
NewTuple *DemoTupleState `json:"newTuple"`
106+
SamePage bool `json:"samePage"`
107+
Explanation string `json:"explanation"`
107108
}
108109

109110
type TreeNode struct {

0 commit comments

Comments
 (0)