MySQL 8.0.29
Source Code Documentation
compare_access_paths.h
Go to the documentation of this file.
1/* Copyright (c) 2021, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef SQL_JOIN_OPTIMIZER_COMPARE_ACCESS_PATHS_H
24#define SQL_JOIN_OPTIMIZER_COMPARE_ACCESS_PATHS_H
25
26#include <assert.h>
27#include <stdint.h>
28
29#include <cmath>
30
33
34enum class FuzzyComparisonResult : uint32_t {
35 IDENTICAL = 0,
36 FIRST_BETTER = 1,
37 SECOND_BETTER = 2,
40};
41
42// Compare x and y with a given fuzz factor under the assumption that the
43// lesser value is preferred. If the relative difference between x and y
44// is small (x and y are fuzzily identical) we still return information
45// about which one is slightly better.
46inline FuzzyComparisonResult FuzzyComparison(double x, double y,
47 double fuzz_factor) {
48 assert(std::isfinite(x));
49 assert(std::isfinite(y));
50 assert(x >= 0);
51 assert(y >= 0);
52
53 if (fuzz_factor * x < y) {
55 } else if (fuzz_factor * y < x) {
57 } else { // Fuzzily identical
58 if (x < y) {
60 } else if (y < x) {
62 } else {
64 }
65 }
66}
67
73};
74
76 const AccessPath &a,
77 const AccessPath &b,
78 OrderingSet obsolete_orderings);
79
80#endif // SQL_JOIN_OPTIMIZER_COMPARE_ACCESS_PATHS_H
Definition: interesting_orders.h:214
PathComparisonResult
Definition: compare_access_paths.h:68
PathComparisonResult CompareAccessPaths(const LogicalOrderings &orderings, const AccessPath &a, const AccessPath &b, OrderingSet obsolete_orderings)
Definition: join_optimizer.cc:3609
FuzzyComparisonResult FuzzyComparison(double x, double y, double fuzz_factor)
Definition: compare_access_paths.h:46
FuzzyComparisonResult
Definition: compare_access_paths.h:34
Tracks which tuple streams follow which orders, and in particular whether they follow interesting ord...
std::bitset< kMaxSupportedOrderings > OrderingSet
Definition: interesting_orders_defs.h:65
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:188