@@ -279,7 +279,10 @@ struct QueryTab: Identifiable, Equatable {
279279 var tabType : TabType
280280
281281 // Results — stored in a reference-type buffer to avoid CoW duplication
282- // of large data when the struct is mutated (MEM-1 fix)
282+ // of large data when the struct is mutated (MEM-1 fix).
283+ // Note: When QueryTab is copied (struct CoW), copies share the same RowBuffer
284+ // instance. This is intentional — RowBuffer is a reference type specifically to
285+ // avoid duplicating large result arrays on every struct mutation.
283286 var rowBuffer : RowBuffer
284287
285288 // Backward-compatible computed accessors for result data
@@ -492,22 +495,35 @@ struct QueryTab: Identifiable, Equatable {
492495 )
493496 }
494497
498+ // Identity-based equality: two QueryTabs are equal if they represent the same tab.
499+ // Content changes (query text, results, filters, etc.) are tracked via resultVersion,
500+ // metadataVersion, and SwiftUI's observation system — not via Equatable.
495501 static func == ( lhs: QueryTab , rhs: QueryTab ) -> Bool {
496502 lhs. id == rhs. id
497- && lhs. title == rhs. title
498- && lhs. isExecuting == rhs. isExecuting
499- && lhs. errorMessage == rhs. errorMessage
500- && lhs. executionTime == rhs. executionTime
501- && lhs. resultVersion == rhs. resultVersion
502- && lhs. pagination == rhs. pagination
503- && lhs. sortState == rhs. sortState
504- && lhs. showStructure == rhs. showStructure
505- && lhs. isEditable == rhs. isEditable
506- && lhs. isView == rhs. isView
507- && lhs. tabType == rhs. tabType
508- && lhs. rowsAffected == rhs. rowsAffected
509- && lhs. isPreview == rhs. isPreview
510- && lhs. hasUserInteraction == rhs. hasUserInteraction
503+ }
504+
505+ /// Hash of content fields that matter for change detection.
506+ /// Use this when you need to know if a tab's visible state has changed
507+ /// (e.g., for caching or diff purposes), rather than relying on Equatable.
508+ var contentHash : Int {
509+ var hasher = Hasher ( )
510+ hasher. combine ( id)
511+ hasher. combine ( title)
512+ hasher. combine ( query)
513+ hasher. combine ( tableName)
514+ hasher. combine ( isExecuting)
515+ hasher. combine ( errorMessage)
516+ hasher. combine ( executionTime)
517+ hasher. combine ( resultVersion)
518+ hasher. combine ( metadataVersion)
519+ hasher. combine ( showStructure)
520+ hasher. combine ( isEditable)
521+ hasher. combine ( isView)
522+ hasher. combine ( tabType)
523+ hasher. combine ( rowsAffected)
524+ hasher. combine ( isPreview)
525+ hasher. combine ( hasUserInteraction)
526+ return hasher. finalize ( )
511527 }
512528}
513529
0 commit comments