Skip to content

Instantly share code, notes, and snippets.

@msirek

msirek/expr.go Secret

Created July 18, 2022 15:10
Show Gist options
  • Save msirek/43e40e010eeb80b983db96892e22b7e6 to your computer and use it in GitHub Desktop.
Save msirek/43e40e010eeb80b983db96892e22b7e6 to your computer and use it in GitHub Desktop.
Detect scans from regional tables that can be satisfied in the local region.
func (s *ScanPrivate) IsLocalOnly(md *opt.Metadata, evalCtx *eval.Context) bool {
tab := md.Table(s.Table)
tabMeta := md.TableMeta(s.Table)
index := tabMeta.Table.Index(s.Index)
homeRegion, hasHomeRegion := tab.HomeRegion()
prefixSorter, ok := tabMeta.IndexPartitionLocality(index.Ordinal(), index, evalCtx)
localRegion, hasLocalRegion := evalCtx.GetLocalRegion()
if s.LocalityOptimized {
return true
} else if tab.IsGlobalTable() {
return true
} else if !ok && !hasHomeRegion {
// Not regional by row or regional by table.
return false
} else if hasHomeRegion {
if !hasLocalRegion || homeRegion != localRegion {
return false
}
return true
} else if !hasLocalRegion || s.Constraint == nil {
return false
} else if s.Constraint.HasRemoteSpans(prefixSorter) {
return false
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment