diff --git a/Makefile b/Makefile index 3a5c80273796..255dde4154d3 100644 --- a/Makefile +++ b/Makefile @@ -771,7 +771,8 @@ $(LIBSNAPPY): $(SNAPPY_DIR)/Makefile bin/uptodate .ALWAYS_REBUILD $(LIBGEOS): $(GEOS_DIR)/Makefile bin/uptodate .ALWAYS_REBUILD @uptodate $@ $(GEOS_SRC_DIR) || $(MAKE) --no-print-directory -C $(GEOS_DIR) geos_c mkdir -p $(DYN_LIB_DIR) - ln -sf $(GEOS_DIR)/lib/lib{geos,geos_c}.$(DYN_EXT) $(DYN_LIB_DIR) + rm -f $(DYN_LIB_DIR)/lib{geos,geos_c}.$(DYN_EXT) + cp -L $(GEOS_DIR)/$(if $(target-is-windows),bin,lib)/lib{geos,geos_c}.$(DYN_EXT) $(DYN_LIB_DIR) $(LIBPROJ): $(PROJ_DIR)/Makefile bin/uptodate .ALWAYS_REBUILD @uptodate $@ $(PROJ_SRC_DIR) || $(MAKE) --no-print-directory -C $(PROJ_DIR) proj diff --git a/pkg/geo/geo.go b/pkg/geo/geo.go index c9b4e0d92cbf..1fad6c23a165 100644 --- a/pkg/geo/geo.go +++ b/pkg/geo/geo.go @@ -472,7 +472,7 @@ func (g *Geography) AsS2(emptyBehavior EmptyBehavior) ([]s2.Region, error) { return S2RegionsFromGeom(geomRepr, emptyBehavior) } -// BoundingRect returns the bounding rectangle of the given Geography. +// BoundingRect returns the bounding s2.Rect of the given Geography. func (g *Geography) BoundingRect() s2.Rect { bbox := g.spatialObject.BoundingBox if bbox == nil { @@ -484,6 +484,11 @@ func (g *Geography) BoundingRect() s2.Rect { } } +// BoundingCap returns the bounding s2.Cap of the given Geography. +func (g *Geography) BoundingCap() s2.Cap { + return g.BoundingRect().CapBound() +} + // IsLinearRingCCW returns whether a given linear ring is counter clock wise. // See 2.07 of http://www.faqs.org/faqs/graphics/algorithms-faq/. // "Find the lowest vertex (or, if there is more than one vertex with the same lowest coordinate, diff --git a/pkg/geo/geogfn/distance.go b/pkg/geo/geogfn/distance.go index ad038adda8df..990559caf4b6 100644 --- a/pkg/geo/geogfn/distance.go +++ b/pkg/geo/geogfn/distance.go @@ -21,6 +21,12 @@ import ( "github.com/golang/geo/s2" ) +// SpheroidErrorFraction is an error fraction to compensate for using a sphere +// to calculate the distance for what is actually a spheroid. The distance +// calculation has an error that is bounded by (2 * spheroid.Flattening)%. +// This 5% margin is pretty safe. +const SpheroidErrorFraction = 0.05 + // Distance returns the distance between geographies a and b on a sphere or spheroid. // Returns a geo.EmptyGeometryError if any of the Geographies are EMPTY. func Distance( @@ -217,12 +223,6 @@ func distanceGeographyRegions( return minDistance, nil } -// SpheroidErrorFraction is an error fraction to compensate for using a sphere -// to calculate the distance for what is actually a spheroid. The distance -// calculation has an error that is bounded by (2 * spheroid.Flattening)%. -// This 5% margin is pretty safe. -const SpheroidErrorFraction = 0.05 - // geographyMinDistanceUpdater finds the minimum distance using a sphere. // Methods will return early if it finds a minimum distance <= stopAfterLE. type geographyMinDistanceUpdater struct { diff --git a/pkg/geo/geogfn/dwithin.go b/pkg/geo/geogfn/dwithin.go index a2ce165f2a34..a3b91cdbcb81 100644 --- a/pkg/geo/geogfn/dwithin.go +++ b/pkg/geo/geogfn/dwithin.go @@ -13,6 +13,7 @@ package geogfn import ( "github.com/cockroachdb/cockroach/pkg/geo" "github.com/cockroachdb/errors" + "github.com/golang/geo/s1" ) // DWithin returns whether a is within distance d of b, i.e. Distance(a, b) <= d. @@ -26,6 +27,18 @@ func DWithin( if distance < 0 { return false, errors.Newf("dwithin distance cannot be less than zero") } + spheroid, err := a.Spheroid() + if err != nil { + return false, err + } + + angleToExpand := s1.Angle(distance / spheroid.SphereRadius) + if useSphereOrSpheroid == UseSpheroid { + angleToExpand *= (1 + SpheroidErrorFraction) + } + if !a.BoundingCap().Expanded(angleToExpand).Intersects(b.BoundingCap()) { + return false, nil + } aRegions, err := a.AsS2(geo.EmptyBehaviorError) if err != nil { @@ -41,10 +54,6 @@ func DWithin( } return false, err } - spheroid, err := a.Spheroid() - if err != nil { - return false, err - } maybeClosestDistance, err := distanceGeographyRegions(spheroid, useSphereOrSpheroid, aRegions, bRegions, distance) if err != nil { return false, err diff --git a/pkg/sql/mutations/mutations.go b/pkg/sql/mutations/mutations.go index d10f61846cf7..bda017afb470 100644 --- a/pkg/sql/mutations/mutations.go +++ b/pkg/sql/mutations/mutations.go @@ -536,7 +536,7 @@ func postgresMutator(rng *rand.Rand, q string) string { var postgresStatementMutator MultiStatementMutation = func(rng *rand.Rand, stmts []tree.Statement) (mutated []tree.Statement, changed bool) { for _, stmt := range stmts { switch stmt := stmt.(type) { - case *tree.SetClusterSetting: + case *tree.SetClusterSetting, *tree.SetVar: continue case *tree.CreateTable: if stmt.Interleave != nil { diff --git a/pkg/sql/opt/memo/expr.go b/pkg/sql/opt/memo/expr.go index d89f5f8e35ca..6b6d28bba4ed 100644 --- a/pkg/sql/opt/memo/expr.go +++ b/pkg/sql/opt/memo/expr.go @@ -552,6 +552,16 @@ func (s *ScanPrivate) IsCanonical() bool { s.HardLimit == 0 } +// IsUnfiltered returns true if the ScanPrivate will produce all rows in the +// table. +func (s *ScanPrivate) IsUnfiltered(md *opt.Metadata) bool { + _, isPartialIndex := md.Table(s.Table).Index(s.Index).Predicate() + return !isPartialIndex && + (s.Constraint == nil || s.Constraint.IsUnconstrained()) && + s.InvertedConstraint == nil && + s.HardLimit == 0 +} + // IsLocking returns true if the ScanPrivate is configured to use a row-level // locking mode. This can be the case either because the Scan is in the scope of // a SELECT .. FOR [KEY] UPDATE/SHARE clause or because the Scan was configured diff --git a/pkg/sql/opt/memo/multiplicity_builder.go b/pkg/sql/opt/memo/multiplicity_builder.go index 5e51ceb710ec..011de1c2aea5 100644 --- a/pkg/sql/opt/memo/multiplicity_builder.go +++ b/pkg/sql/opt/memo/multiplicity_builder.go @@ -115,9 +115,9 @@ func deriveUnfilteredCols(in RelExpr) opt.ColSet { // non-null foreign key relation - rows in kr imply rows in xy. However, // the columns from xy are not output columns, so in order to see that this // is the case we must bubble up non-output columns. - baseTable := t.Memo().Metadata().Table(t.Table) - _, isPartialIndex := baseTable.Index(t.Index).Predicate() - if t.HardLimit == 0 && t.Constraint == nil && !isPartialIndex { + md := t.Memo().Metadata() + baseTable := md.Table(t.Table) + if t.IsUnfiltered(md) { for i, cnt := 0, baseTable.ColumnCount(); i < cnt; i++ { unfilteredCols.Add(t.Table.ColumnID(i)) } diff --git a/pkg/sql/opt/opbench/testdata/scan-lineitem.csv b/pkg/sql/opt/opbench/testdata/scan-lineitem.csv index 73c78926ac72..3b2adbef6385 100644 --- a/pkg/sql/opt/opbench/testdata/scan-lineitem.csv +++ b/pkg/sql/opt/opbench/testdata/scan-lineitem.csv @@ -1,31 +1,31 @@ rows,num_cols,estimated,actual -1000000,1,1170000.020000,0.834084 -2000000,1,2340000.020000,1.489845 -3000000,1,3510000.020000,2.211772 -4000000,1,4680000.020000,2.787555 -5000000,1,5850000.020000,3.727968 -6000000,1,7020000.020000,4.538592 -1000000,2,1180000.020000,0.856709 -2000000,2,2360000.020000,1.689832 -3000000,2,3540000.020000,2.624644 -4000000,2,4720000.020000,3.354893 -5000000,2,5900000.020000,4.149957 -6000000,2,7080000.020000,5.126522 -1000000,3,1190000.020000,0.948950 -2000000,3,2380000.020000,1.844214 -3000000,3,3570000.020000,2.819678 -4000000,3,4760000.020000,3.689639 -5000000,3,5950000.020000,4.598679 -6000000,3,7140000.020000,5.589131 -1000000,4,1200000.020000,0.963368 -2000000,4,2400000.020000,1.907634 -3000000,4,3600000.020000,2.819860 -4000000,4,4800000.020000,3.835917 -5000000,4,6000000.020000,4.603531 -6000000,4,7200000.020000,5.676630 -1000000,16,1320000.020000,1.951303 -2000000,16,2640000.020000,3.845009 -3000000,16,3960000.020000,5.823685 -4000000,16,5280000.020000,7.786907 -5000000,16,6600000.020000,9.746737 -6000000,16,7920000.020000,11.603873 +1000000,1,1170000.010000,0.834084 +2000000,1,2340000.010000,1.489845 +3000000,1,3510000.010000,2.211772 +4000000,1,4680000.010000,2.787555 +5000000,1,5850000.010000,3.727968 +6000000,1,7020000.010000,4.538592 +1000000,2,1180000.010000,0.856709 +2000000,2,2360000.010000,1.689832 +3000000,2,3540000.010000,2.624644 +4000000,2,4720000.010000,3.354893 +5000000,2,5900000.010000,4.149957 +6000000,2,7080000.010000,5.126522 +1000000,3,1190000.010000,0.948950 +2000000,3,2380000.010000,1.844214 +3000000,3,3570000.010000,2.819678 +4000000,3,4760000.010000,3.689639 +5000000,3,5950000.010000,4.598679 +6000000,3,7140000.010000,5.589131 +1000000,4,1200000.010000,0.963368 +2000000,4,2400000.010000,1.907634 +3000000,4,3600000.010000,2.819860 +4000000,4,4800000.010000,3.835917 +5000000,4,6000000.010000,4.603531 +6000000,4,7200000.010000,5.676630 +1000000,16,1320000.010000,1.951303 +2000000,16,2640000.010000,3.845009 +3000000,16,3960000.010000,5.823685 +4000000,16,5280000.010000,7.786907 +5000000,16,6600000.010000,9.746737 +6000000,16,7920000.010000,11.603873 diff --git a/pkg/sql/opt/opbench/testdata/scan-orders.csv b/pkg/sql/opt/opbench/testdata/scan-orders.csv index dd8295760108..b24e027f1a9a 100644 --- a/pkg/sql/opt/opbench/testdata/scan-orders.csv +++ b/pkg/sql/opt/opbench/testdata/scan-orders.csv @@ -1,25 +1,25 @@ rows,num_cols,estimated,actual -250000,1,275000.020000,0.234685 -500000,1,550000.020000,0.355673 -750000,1,825000.020000,0.536125 -1000000,1,1100000.020000,0.735832 -1250000,1,1375000.020000,0.909200 -1500000,1,1650000.020000,1.036382 -250000,3,280000.020000,0.226567 -500000,3,560000.020000,0.441384 -750000,3,840000.020000,0.611747 -1000000,3,1120000.020000,0.881042 -1250000,3,1400000.020000,1.092393 -1500000,3,1680000.020000,1.314116 -250000,6,287500.020000,0.292452 -500000,6,575000.020000,0.496511 -750000,6,862500.020000,0.817809 -1000000,6,1150000.020000,1.162477 -1250000,6,1437500.020000,1.451609 -1500000,6,1725000.020000,1.760463 -250000,9,295000.020000,0.360331 -500000,9,590000.020000,0.626732 -750000,9,885000.020000,0.992292 -1000000,9,1180000.020000,1.368585 -1250000,9,1475000.020000,1.727139 -1500000,9,1770000.020000,2.056275 +250000,1,275000.010000,0.234685 +500000,1,550000.010000,0.355673 +750000,1,825000.010000,0.536125 +1000000,1,1100000.010000,0.735832 +1250000,1,1375000.010000,0.909200 +1500000,1,1650000.010000,1.036382 +250000,3,280000.010000,0.226567 +500000,3,560000.010000,0.441384 +750000,3,840000.010000,0.611747 +1000000,3,1120000.010000,0.881042 +1250000,3,1400000.010000,1.092393 +1500000,3,1680000.010000,1.314116 +250000,6,287500.010000,0.292452 +500000,6,575000.010000,0.496511 +750000,6,862500.010000,0.817809 +1000000,6,1150000.010000,1.162477 +1250000,6,1437500.010000,1.451609 +1500000,6,1725000.010000,1.760463 +250000,9,295000.010000,0.360331 +500000,9,590000.010000,0.626732 +750000,9,885000.010000,0.992292 +1000000,9,1180000.010000,1.368585 +1250000,9,1475000.010000,1.727139 +1500000,9,1770000.010000,2.056275 diff --git a/pkg/sql/opt/opbench/testdata/sort-lineitem.csv b/pkg/sql/opt/opbench/testdata/sort-lineitem.csv index dbbfc987e072..7a8e4899fd75 100644 --- a/pkg/sql/opt/opbench/testdata/sort-lineitem.csv +++ b/pkg/sql/opt/opbench/testdata/sort-lineitem.csv @@ -1,19 +1,19 @@ rows,num_cols,estimated,actual -1000000,1,1588631.401386,1.467528 -2000000,1,3217262.772773,3.007519 -3000000,1,4860991.894203,5.827569 -4000000,1,6514525.515546,7.106306 -5000000,1,8175349.696421,8.982024 -6000000,1,9841983.758405,10.749726 -1000000,2,1598631.401386,1.665857 -2000000,2,3237262.772773,4.036806 -3000000,2,4890991.894203,6.109568 -4000000,2,6554525.515546,8.072787 -5000000,2,8225349.696421,9.743525 -6000000,2,9901983.758405,12.756862 -1000000,3,1608631.401386,2.786447 -2000000,3,3257262.772773,4.812669 -3000000,3,4920991.894203,7.417335 -4000000,3,6594525.515546,11.088666 -5000000,3,8275349.696421,12.703216 -6000000,3,9961983.758405,14.615791 +1000000,1,1588631.391386,1.467528 +2000000,1,3217262.762773,3.007519 +3000000,1,4860991.884203,5.827569 +4000000,1,6514525.505546,7.106306 +5000000,1,8175349.686421,8.982024 +6000000,1,9841983.748405,10.749726 +1000000,2,1598631.391386,1.665857 +2000000,2,3237262.762773,4.036806 +3000000,2,4890991.884203,6.109568 +4000000,2,6554525.505546,8.072787 +5000000,2,8225349.686421,9.743525 +6000000,2,9901983.748405,12.756862 +1000000,3,1608631.391386,2.786447 +2000000,3,3257262.762773,4.812669 +3000000,3,4920991.884203,7.417335 +4000000,3,6594525.505546,11.088666 +5000000,3,8275349.686421,12.703216 +6000000,3,9961983.748405,14.615791 diff --git a/pkg/sql/opt/opbench/testdata/tpch-hash-join.csv b/pkg/sql/opt/opbench/testdata/tpch-hash-join.csv index 7f461304a8ff..8584fc7466e6 100644 --- a/pkg/sql/opt/opbench/testdata/tpch-hash-join.csv +++ b/pkg/sql/opt/opbench/testdata/tpch-hash-join.csv @@ -1,61 +1,61 @@ lineitem_rows,supplier_rows,estimated,actual -1000000,1000,1059539.161521,0.632029 -1000000,2000,1061578.273042,0.570772 -1000000,3000,1063617.384562,0.598398 -1000000,4000,1065656.496083,0.617674 -1000000,5000,1067695.607604,0.646713 -1000000,6000,1069734.719125,0.670244 -1000000,7000,1071773.830646,0.696637 -1000000,8000,1073812.942167,0.714715 -1000000,9000,1075852.053687,0.751317 -1000000,10000,1077891.165208,0.768779 -2000000,1000,2118035.773042,1.138285 -2000000,2000,2121071.496083,1.138734 -2000000,3000,2124107.219125,1.282786 -2000000,4000,2127142.942167,1.280636 -2000000,5000,2130178.665208,1.312094 -2000000,6000,2133214.388250,1.349938 -2000000,7000,2136250.111292,1.419143 -2000000,8000,2139285.834333,1.464272 -2000000,9000,2142321.557375,1.517473 -2000000,10000,2145357.280417,1.665660 -3000000,1000,3176532.384562,1.723738 -3000000,2000,3180564.719125,1.846815 -3000000,3000,3184597.053687,1.898967 -3000000,4000,3188629.388250,2.007566 -3000000,5000,3192661.722812,2.114909 -3000000,6000,3196694.057375,2.131143 -3000000,7000,3200726.391937,2.195418 -3000000,8000,3204758.726500,2.289942 -3000000,9000,3208791.061062,2.392428 -3000000,10000,3212823.395625,2.583456 -4000000,1000,4235028.996083,2.372955 -4000000,2000,4240057.942167,2.577938 -4000000,3000,4245086.888250,2.751925 -4000000,4000,4250115.834333,2.841285 -4000000,5000,4255144.780417,2.787714 -4000000,6000,4260173.726500,2.886389 -4000000,7000,4265202.672583,3.053209 -4000000,8000,4270231.618667,3.089117 -4000000,9000,4275260.564750,3.175184 -4000000,10000,4280289.510833,3.333599 -5000000,1000,5293525.607604,2.949502 -5000000,2000,5299551.165208,3.096689 -5000000,3000,5305576.722812,3.231915 -5000000,4000,5311602.280417,3.415585 -5000000,5000,5317627.838021,3.470487 -5000000,6000,5323653.395625,3.691811 -5000000,7000,5329678.953229,3.747602 -5000000,8000,5335704.510833,3.808640 -5000000,9000,5341730.068437,4.090677 -5000000,10000,5347755.626041,4.145000 -6000000,1000,6352022.219125,3.547718 -6000000,2000,6359044.388250,3.729800 -6000000,3000,6366066.557375,3.814457 -6000000,4000,6373088.726500,4.056065 -6000000,5000,6380110.895625,4.093838 -6000000,6000,6387133.064750,4.332647 -6000000,7000,6394155.233875,4.503540 -6000000,8000,6401177.403000,4.591593 -6000000,9000,6408199.572125,4.831284 -6000000,10000,6415221.741250,5.117229 +1000000,1000,1059539.141521,0.632029 +1000000,2000,1061578.253042,0.570772 +1000000,3000,1063617.364562,0.598398 +1000000,4000,1065656.476083,0.617674 +1000000,5000,1067695.587604,0.646713 +1000000,6000,1069734.699125,0.670244 +1000000,7000,1071773.810646,0.696637 +1000000,8000,1073812.922167,0.714715 +1000000,9000,1075852.033687,0.751317 +1000000,10000,1077891.145208,0.768779 +2000000,1000,2118035.753042,1.138285 +2000000,2000,2121071.476083,1.138734 +2000000,3000,2124107.199125,1.282786 +2000000,4000,2127142.922167,1.280636 +2000000,5000,2130178.645208,1.312094 +2000000,6000,2133214.368250,1.349938 +2000000,7000,2136250.091292,1.419143 +2000000,8000,2139285.814333,1.464272 +2000000,9000,2142321.537375,1.517473 +2000000,10000,2145357.260417,1.665660 +3000000,1000,3176532.364562,1.723738 +3000000,2000,3180564.699125,1.846815 +3000000,3000,3184597.033687,1.898967 +3000000,4000,3188629.368250,2.007566 +3000000,5000,3192661.702812,2.114909 +3000000,6000,3196694.037375,2.131143 +3000000,7000,3200726.371937,2.195418 +3000000,8000,3204758.706500,2.289942 +3000000,9000,3208791.041062,2.392428 +3000000,10000,3212823.375625,2.583456 +4000000,1000,4235028.976083,2.372955 +4000000,2000,4240057.922167,2.577938 +4000000,3000,4245086.868250,2.751925 +4000000,4000,4250115.814333,2.841285 +4000000,5000,4255144.760417,2.787714 +4000000,6000,4260173.706500,2.886389 +4000000,7000,4265202.652583,3.053209 +4000000,8000,4270231.598667,3.089117 +4000000,9000,4275260.544750,3.175184 +4000000,10000,4280289.490833,3.333599 +5000000,1000,5293525.587604,2.949502 +5000000,2000,5299551.145208,3.096689 +5000000,3000,5305576.702812,3.231915 +5000000,4000,5311602.260417,3.415585 +5000000,5000,5317627.818021,3.470487 +5000000,6000,5323653.375625,3.691811 +5000000,7000,5329678.933229,3.747602 +5000000,8000,5335704.490833,3.808640 +5000000,9000,5341730.048437,4.090677 +5000000,10000,5347755.606041,4.145000 +6000000,1000,6352022.199125,3.547718 +6000000,2000,6359044.368250,3.729800 +6000000,3000,6366066.537375,3.814457 +6000000,4000,6373088.706500,4.056065 +6000000,5000,6380110.875625,4.093838 +6000000,6000,6387133.044750,4.332647 +6000000,7000,6394155.213875,4.503540 +6000000,8000,6401177.383000,4.591593 +6000000,9000,6408199.552125,4.831284 +6000000,10000,6415221.721250,5.117229 diff --git a/pkg/sql/opt/opbench/testdata/tpch-lookup-join.csv b/pkg/sql/opt/opbench/testdata/tpch-lookup-join.csv index 9f6f3037106f..0d10831ebc9d 100644 --- a/pkg/sql/opt/opbench/testdata/tpch-lookup-join.csv +++ b/pkg/sql/opt/opbench/testdata/tpch-lookup-join.csv @@ -1,11 +1,11 @@ supplier_rows,estimated,actual -1000,1225129.551626,0.956943 -2000,2450259.073253,1.718082 -3000,3675388.594879,2.448982 -4000,4900518.116506,3.256364 -5000,6125647.638132,3.989822 -6000,7350777.159759,4.934962 -7000,8575906.681385,5.711155 -8000,9801036.203012,6.269443 -9000,11026165.724638,7.126775 -10000,12251295.246265,7.803261 +1000,1225129.541626,0.956943 +2000,2450259.063253,1.718082 +3000,3675388.584879,2.448982 +4000,4900518.106506,3.256364 +5000,6125647.628132,3.989822 +6000,7350777.149759,4.934962 +7000,8575906.671385,5.711155 +8000,9801036.193012,6.269443 +9000,11026165.714638,7.126775 +10000,12251295.236265,7.803261 diff --git a/pkg/sql/opt/opbench/testdata/tpch-merge-join.csv b/pkg/sql/opt/opbench/testdata/tpch-merge-join.csv index 4624d9416692..9ffb6cd1ccf0 100644 --- a/pkg/sql/opt/opbench/testdata/tpch-merge-join.csv +++ b/pkg/sql/opt/opbench/testdata/tpch-merge-join.csv @@ -1,61 +1,61 @@ lineitem_rows,supplier_rows,estimated,actual -1000000,1000,1052086.661521,0.655957 -1000000,2000,1054173.273042,0.684236 -1000000,3000,1056259.884562,0.613559 -1000000,4000,1058346.496083,0.612945 -1000000,5000,1060433.107604,0.616786 -1000000,6000,1062519.719125,0.617186 -1000000,7000,1064606.330646,0.618434 -1000000,8000,1066692.942167,0.625451 -1000000,9000,1068779.553687,0.648479 -1000000,10000,1070866.165208,0.609943 -2000000,1000,2103083.273042,1.121597 -2000000,2000,2106166.496083,1.157962 -2000000,3000,2109249.719125,1.248894 -2000000,4000,2112332.942167,1.333210 -2000000,5000,2115416.165208,1.275761 -2000000,6000,2118499.388250,1.281630 -2000000,7000,2121582.611292,1.257683 -2000000,8000,2124665.834333,1.256249 -2000000,9000,2127749.057375,1.265444 -2000000,10000,2130832.280417,1.254755 -3000000,1000,3154079.884562,1.640085 -3000000,2000,3158159.719125,1.870265 -3000000,3000,3162239.553687,1.865659 -3000000,4000,3166319.388250,1.897811 -3000000,5000,3170399.222812,2.029875 -3000000,6000,3174479.057375,1.998668 -3000000,7000,3178558.891937,2.071311 -3000000,8000,3182638.726500,1.984700 -3000000,9000,3186718.561062,1.981228 -3000000,10000,3190798.395625,2.016296 -4000000,1000,4205076.496083,2.294018 -4000000,2000,4210152.942167,2.424131 -4000000,3000,4215229.388250,2.476990 -4000000,4000,4220305.834333,2.664103 -4000000,5000,4225382.280417,2.635390 -4000000,6000,4230458.726500,2.817420 -4000000,7000,4235535.172583,2.913923 -4000000,8000,4240611.618667,2.936510 -4000000,9000,4245688.064750,3.014648 -4000000,10000,4250764.510833,3.089238 -5000000,1000,5256073.107604,2.924274 -5000000,2000,5262146.165208,3.084452 -5000000,3000,5268219.222812,3.634944 -5000000,4000,5274292.280417,3.165605 -5000000,5000,5280365.338021,3.255726 -5000000,6000,5286438.395625,3.276324 -5000000,7000,5292511.453229,3.275704 -5000000,8000,5298584.510833,3.340096 -5000000,9000,5304657.568437,3.295898 -5000000,10000,5310730.626041,3.298758 -6000000,1000,6307069.719125,3.381934 -6000000,2000,6314139.388250,3.385488 -6000000,3000,6321209.057375,3.471299 -6000000,4000,6328278.726500,3.599497 -6000000,5000,6335348.395625,3.588051 -6000000,6000,6342418.064750,3.696527 -6000000,7000,6349487.733875,3.828929 -6000000,8000,6356557.403000,3.806838 -6000000,9000,6363627.072125,3.902904 -6000000,10000,6370696.741250,4.002708 +1000000,1000,1052086.641521,0.655957 +1000000,2000,1054173.253042,0.684236 +1000000,3000,1056259.864562,0.613559 +1000000,4000,1058346.476083,0.612945 +1000000,5000,1060433.087604,0.616786 +1000000,6000,1062519.699125,0.617186 +1000000,7000,1064606.310646,0.618434 +1000000,8000,1066692.922167,0.625451 +1000000,9000,1068779.533687,0.648479 +1000000,10000,1070866.145208,0.609943 +2000000,1000,2103083.253042,1.121597 +2000000,2000,2106166.476083,1.157962 +2000000,3000,2109249.699125,1.248894 +2000000,4000,2112332.922167,1.333210 +2000000,5000,2115416.145208,1.275761 +2000000,6000,2118499.368250,1.281630 +2000000,7000,2121582.591292,1.257683 +2000000,8000,2124665.814333,1.256249 +2000000,9000,2127749.037375,1.265444 +2000000,10000,2130832.260417,1.254755 +3000000,1000,3154079.864562,1.640085 +3000000,2000,3158159.699125,1.870265 +3000000,3000,3162239.533687,1.865659 +3000000,4000,3166319.368250,1.897811 +3000000,5000,3170399.202812,2.029875 +3000000,6000,3174479.037375,1.998668 +3000000,7000,3178558.871937,2.071311 +3000000,8000,3182638.706500,1.984700 +3000000,9000,3186718.541062,1.981228 +3000000,10000,3190798.375625,2.016296 +4000000,1000,4205076.476083,2.294018 +4000000,2000,4210152.922167,2.424131 +4000000,3000,4215229.368250,2.476990 +4000000,4000,4220305.814333,2.664103 +4000000,5000,4225382.260417,2.635390 +4000000,6000,4230458.706500,2.817420 +4000000,7000,4235535.152583,2.913923 +4000000,8000,4240611.598667,2.936510 +4000000,9000,4245688.044750,3.014648 +4000000,10000,4250764.490833,3.089238 +5000000,1000,5256073.087604,2.924274 +5000000,2000,5262146.145208,3.084452 +5000000,3000,5268219.202812,3.634944 +5000000,4000,5274292.260417,3.165605 +5000000,5000,5280365.318021,3.255726 +5000000,6000,5286438.375625,3.276324 +5000000,7000,5292511.433229,3.275704 +5000000,8000,5298584.490833,3.340096 +5000000,9000,5304657.548437,3.295898 +5000000,10000,5310730.606041,3.298758 +6000000,1000,6307069.699125,3.381934 +6000000,2000,6314139.368250,3.385488 +6000000,3000,6321209.037375,3.471299 +6000000,4000,6328278.706500,3.599497 +6000000,5000,6335348.375625,3.588051 +6000000,6000,6342418.044750,3.696527 +6000000,7000,6349487.713875,3.828929 +6000000,8000,6356557.383000,3.806838 +6000000,9000,6363627.052125,3.902904 +6000000,10000,6370696.721250,4.002708 diff --git a/pkg/sql/opt/optgen/exprgen/testdata/join b/pkg/sql/opt/optgen/exprgen/testdata/join index 39fe5169032b..bcdd597b208c 100644 --- a/pkg/sql/opt/optgen/exprgen/testdata/join +++ b/pkg/sql/opt/optgen/exprgen/testdata/join @@ -176,12 +176,12 @@ index-join abc ├── columns: t.public.abc.c:3(int) ├── cardinality: [0 - 10] ├── stats: [rows=10] - ├── cost: 51.03 + ├── cost: 51.02 ├── interesting orderings: (+1) └── scan t.public.abc@ab ├── columns: t.public.abc.a:1(int) ├── limit: 10 ├── stats: [rows=10] - ├── cost: 10.42 + ├── cost: 10.41 ├── prune: (1) └── interesting orderings: (+1) diff --git a/pkg/sql/opt/xform/coster.go b/pkg/sql/opt/xform/coster.go index 0167efd6c171..5a62e5f79e67 100644 --- a/pkg/sql/opt/xform/coster.go +++ b/pkg/sql/opt/xform/coster.go @@ -314,8 +314,7 @@ func (c *coster) computeScanCost(scan *memo.ScanExpr, required *physical.Require // will prefer a constrained scan. This is important if our row count // estimate turns out to be smaller than the actual row count. var preferConstrainedScanCost memo.Cost - if (scan.Constraint == nil || scan.Constraint.IsUnconstrained()) && - scan.InvertedConstraint == nil { + if scan.IsUnfiltered(c.mem.Metadata()) { preferConstrainedScanCost = cpuCostFactor } return memo.Cost(rowCount)*(seqIOCostFactor+perRowCost) + preferConstrainedScanCost diff --git a/pkg/sql/opt/xform/custom_funcs.go b/pkg/sql/opt/xform/custom_funcs.go index 780b768a3452..19ca87e9fe1e 100644 --- a/pkg/sql/opt/xform/custom_funcs.go +++ b/pkg/sql/opt/xform/custom_funcs.go @@ -1194,7 +1194,7 @@ func (c *CustomFuncs) LimitScanPrivate( // possible when the required ordering of the rows to be limited can be // satisfied by the Scan operator. // -// NOTE: Limiting unconstrained scans is done by the PushLimitIntoScan rule, +// NOTE: Limiting unconstrained scans is done by the GenerateLimitedScans rule, // since that can require IndexJoin operators to be generated. func (c *CustomFuncs) CanLimitConstrainedScan( scanPrivate *memo.ScanPrivate, required physical.OrderingChoice, @@ -1207,8 +1207,8 @@ func (c *CustomFuncs) CanLimitConstrainedScan( } if scanPrivate.Constraint == nil { - // This is not a constrained scan, so skip it. The PushLimitIntoScan rule - // is responsible for limited unconstrained scans. + // This is not a constrained scan, so skip it. The GenerateLimitedScans + // rule is responsible for limited unconstrained scans. return false } diff --git a/pkg/sql/opt/xform/testdata/rules/groupby b/pkg/sql/opt/xform/testdata/rules/groupby index 72a7cf1470c6..2cc3400328fd 100644 --- a/pkg/sql/opt/xform/testdata/rules/groupby +++ b/pkg/sql/opt/xform/testdata/rules/groupby @@ -494,7 +494,7 @@ memo (optimized, ~5KB, required=[presentation: min:5]) ├── G1: (scalar-group-by G2 G3 cols=()) (scalar-group-by G4 G5 cols=()) │ └── [presentation: min:5] │ ├── best: (scalar-group-by G4 G5 cols=()) - │ └── cost: 1.11 + │ └── cost: 1.10 ├── G2: (scan abc,cols=(1)) │ ├── [ordering: +1] [limit hint: 1.00] │ │ ├── best: (scan abc,cols=(1)) @@ -506,7 +506,7 @@ memo (optimized, ~5KB, required=[presentation: min:5]) ├── G4: (limit G2 G7 ordering=+1) (scan abc,cols=(1),lim=1) │ └── [] │ ├── best: (scan abc,cols=(1),lim=1) - │ └── cost: 1.07 + │ └── cost: 1.06 ├── G5: (aggregations G8) ├── G6: (min G9) ├── G7: (const 1) @@ -556,7 +556,7 @@ memo (optimized, ~5KB, required=[presentation: max:5]) ├── G1: (scalar-group-by G2 G3 cols=()) (scalar-group-by G4 G5 cols=()) │ └── [presentation: max:5] │ ├── best: (scalar-group-by G4 G5 cols=()) - │ └── cost: 1.11 + │ └── cost: 1.10 ├── G2: (scan abc,cols=(1)) │ ├── [ordering: -1] [limit hint: 1.00] │ │ ├── best: (scan abc,rev,cols=(1)) @@ -568,7 +568,7 @@ memo (optimized, ~5KB, required=[presentation: max:5]) ├── G4: (limit G2 G7 ordering=-1) (scan abc,rev,cols=(1),lim=1(rev)) │ └── [] │ ├── best: (scan abc,rev,cols=(1),lim=1(rev)) - │ └── cost: 1.07 + │ └── cost: 1.06 ├── G5: (aggregations G8) ├── G6: (max G9) ├── G7: (const 1) diff --git a/pkg/sql/opt/xform/testdata/rules/scan b/pkg/sql/opt/xform/testdata/rules/scan index d0f14ac0c529..305e2b64c294 100644 --- a/pkg/sql/opt/xform/testdata/rules/scan +++ b/pkg/sql/opt/xform/testdata/rules/scan @@ -57,10 +57,10 @@ memo (optimized, ~4KB, required=[presentation: k:1,f:3] [ordering: -1]) ├── G1: (limit G2 G3 ordering=-1) (scan a,rev,cols=(1,3),lim=10(rev)) │ ├── [presentation: k:1,f:3] [ordering: -1] │ │ ├── best: (scan a,rev,cols=(1,3),lim=10(rev)) - │ │ └── cost: 11.05 + │ │ └── cost: 11.04 │ └── [] │ ├── best: (scan a,rev,cols=(1,3),lim=10(rev)) - │ └── cost: 11.05 + │ └── cost: 11.04 ├── G2: (scan a,cols=(1,3)) (scan a@s_idx,cols=(1,3)) │ ├── [ordering: -1] [limit hint: 10.00] │ │ ├── best: (scan a,rev,cols=(1,3)) diff --git a/pkg/sql/opt/xform/testdata/rules/select b/pkg/sql/opt/xform/testdata/rules/select index 19162f38e634..35abaf184e4b 100644 --- a/pkg/sql/opt/xform/testdata/rules/select +++ b/pkg/sql/opt/xform/testdata/rules/select @@ -173,7 +173,7 @@ memo (optimized, ~7KB, required=[presentation: b:4]) ├── G6: (scan p@if_s,partial,cols=(3,5)) │ └── [] │ ├── best: (scan p@if_s,partial,cols=(3,5)) - │ └── cost: 1060.02 + │ └── cost: 1060.01 ├── G7: (eq G8 G9) ├── G8: (variable s) └── G9: (const 'foo') @@ -204,13 +204,13 @@ memo (optimized, ~8KB, required=[presentation: b:4]) ├── G6: (select G9 G10) │ └── [] │ ├── best: (select G9 G10) - │ └── cost: 1090.03 + │ └── cost: 1090.02 ├── G7: (eq G11 G12) ├── G8: (or G13 G14) ├── G9: (scan p@if_s,partial,cols=(1-3,5)) │ └── [] │ ├── best: (scan p@if_s,partial,cols=(1-3,5)) - │ └── cost: 1080.02 + │ └── cost: 1080.01 ├── G10: (filters G8) ├── G11: (variable s) ├── G12: (const 'foo') @@ -246,14 +246,14 @@ memo (optimized, ~8KB, required=[presentation: b:4]) ├── G6: (index-join G10 p,cols=(3,4)) │ └── [] │ ├── best: (index-join G10 p,cols=(3,4)) - │ └── cost: 5140.03 + │ └── cost: 5140.02 ├── G7: (filters G9) ├── G8: (eq G11 G12) ├── G9: (variable b) ├── G10: (scan p@if_s,partial,cols=(3,5)) │ └── [] │ ├── best: (scan p@if_s,partial,cols=(3,5)) - │ └── cost: 1060.02 + │ └── cost: 1060.01 ├── G11: (variable s) └── G12: (const 'foo') @@ -282,7 +282,7 @@ memo (optimized, ~9KB, required=[presentation: b:4]) ├── G6: (index-join G11 p,cols=(1,3,4)) │ └── [] │ ├── best: (index-join G11 p,cols=(1,3,4)) - │ └── cost: 1120.94 + │ └── cost: 1120.93 ├── G7: (filters G10) ├── G8: (eq G12 G13) ├── G9: (eq G14 G15) @@ -290,7 +290,7 @@ memo (optimized, ~9KB, required=[presentation: b:4]) ├── G11: (select G16 G17) │ └── [] │ ├── best: (select G16 G17) - │ └── cost: 1080.03 + │ └── cost: 1080.02 ├── G12: (variable s) ├── G13: (const 'foo') ├── G14: (variable i) @@ -298,7 +298,7 @@ memo (optimized, ~9KB, required=[presentation: b:4]) ├── G16: (scan p@if_s,partial,cols=(1,3,5)) │ └── [] │ ├── best: (scan p@if_s,partial,cols=(1,3,5)) - │ └── cost: 1070.02 + │ └── cost: 1070.01 └── G17: (filters G9) # Generate multiple partial index scans when there are multiple partial indexes @@ -319,12 +319,12 @@ memo (optimized, ~11KB, required=[presentation: i:1,s:2,b:3]) ├── G4: (index-join G11 q,cols=(1-3)) │ └── [] │ ├── best: (index-join G11 q,cols=(1-3)) - │ └── cost: 5120.03 + │ └── cost: 5120.02 ├── G5: (filters G10) ├── G6: (index-join G12 q,cols=(1-3)) │ └── [] │ ├── best: (index-join G12 q,cols=(1-3)) - │ └── cost: 5120.03 + │ └── cost: 5120.02 ├── G7: (filters G9) ├── G8: (index-join G13 q,cols=(1-3)) │ └── [] @@ -335,11 +335,11 @@ memo (optimized, ~11KB, required=[presentation: i:1,s:2,b:3]) ├── G11: (scan q@i_gt_0,partial,cols=(1,4)) │ └── [] │ ├── best: (scan q@i_gt_0,partial,cols=(1,4)) - │ └── cost: 1040.02 + │ └── cost: 1040.01 ├── G12: (scan q@s_eq_foo,partial,cols=(2,4)) │ └── [] │ ├── best: (scan q@s_eq_foo,partial,cols=(2,4)) - │ └── cost: 1040.02 + │ └── cost: 1040.01 ├── G13: (scan q@i,cols=(1,4),constrained) │ └── [] │ ├── best: (scan q@i,cols=(1,4),constrained)