MySQL 9.1.0
Source Code Documentation
compare_access_paths.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_JOIN_OPTIMIZER_COMPARE_ACCESS_PATHS_H
25#define SQL_JOIN_OPTIMIZER_COMPARE_ACCESS_PATHS_H
26
27#include <assert.h>
28#include <stdint.h>
29
30#include <cmath>
31
34
35enum class FuzzyComparisonResult : uint32_t {
36 IDENTICAL = 0,
37 FIRST_BETTER = 1,
38 SECOND_BETTER = 2,
41};
42
43// Compare x and y with a given fuzz factor under the assumption that the
44// lesser value is preferred. If the relative difference between x and y
45// is small (x and y are fuzzily identical) we still return information
46// about which one is slightly better.
47inline FuzzyComparisonResult FuzzyComparison(double x, double y,
48 double fuzz_factor) {
49 assert(std::isfinite(x));
50 assert(std::isfinite(y));
51 assert(x >= 0);
52 assert(y >= 0);
53
54 if (fuzz_factor * x < y) {
56 } else if (fuzz_factor * y < x) {
58 } else { // Fuzzily identical
59 if (x < y) {
61 } else if (y < x) {
63 } else {
65 }
66 }
67}
68
74};
75
77 const AccessPath &a,
78 const AccessPath &b,
79 OrderingSet obsolete_orderings);
80
81#endif // SQL_JOIN_OPTIMIZER_COMPARE_ACCESS_PATHS_H
Definition: interesting_orders.h:315
PathComparisonResult
Definition: compare_access_paths.h:69
PathComparisonResult CompareAccessPaths(const LogicalOrderings &orderings, const AccessPath &a, const AccessPath &b, OrderingSet obsolete_orderings)
Definition: join_optimizer.cc:5817
FuzzyComparisonResult FuzzyComparison(double x, double y, double fuzz_factor)
Definition: compare_access_paths.h:47
FuzzyComparisonResult
Definition: compare_access_paths.h:35
Tracks which tuple streams follow which orders, and in particular whether they follow interesting ord...
std::bitset< kMaxSupportedOrderings > OrderingSet
Definition: interesting_orders_defs.h:66
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:227