interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / ext / misc / optname.c

113 lines · 3916 bytes Raw Blame History
1/*
2** 2026-10-10
3**
4** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
6**
7** May you do good and not evil.
8** May you find forgiveness for yourself and forgive others.
9** May you share freely, never taking more than you give.
10**
11*************************************************************************
12**
13** The sqlite3_test_control() interface with SQLITE_TESTCTRL_OPTIMIZATIONS
14** and SQLITE_TESTCTRL_GETOPT are used to enable and/or disable various
15** optimizations within SQLite. Optimizations are identified by a bitmask.
16** This file contains external code that will map symbolic names into
17** bitmask values, and bitmask values into symbolic names.
18**
19** This code is not part of the SQLite core because we don't want to use
20** code space to store all the symbolic names.
21*/
22#include "sqlite3.h"
23
24/*
25** Convert an optimization number (as recorded in sqliteInt.h) into
26** a mask for that optimization.
27*/
28#define OPT_MASK(N) ((1ull)<<((N)-1))
29
30
31/*
32** This is the mapping between bits and names.
33**
34** Some bit values have multiple names. The preferred name always
35** comes first.
36*/
37static const struct OptName {
38 sqlite3_uint64 uMask;
39 const char *zName;
40} aOpt[] = {
41 { OPT_MASK(1), "QueryFlattener" },
42 { OPT_MASK(1), "Flatten" }, /* Alias for prior */
43 { OPT_MASK(2), "WindowFunc" },
44 { OPT_MASK(3), "GroupByOrder" },
45 { OPT_MASK(4), "JoinMiss" },
46 { OPT_MASK(5), "DistinctOpt" },
47 { OPT_MASK(6), "CoverIdxScan" },
48 { OPT_MASK(7), "OrderByIdxJoin" },
49 { OPT_MASK(8), "Transitive" },
50 { OPT_MASK(9), "OmitNoopJoin" },
51 { OPT_MASK(10), "CountOfView" },
52 { OPT_MASK(11), "CursorHints" },
53 { OPT_MASK(12), "Stat4" },
54 { OPT_MASK(13), "PushDown" },
55 { OPT_MASK(14), "SimplifyJoin" },
56 { OPT_MASK(15), "SkipScan" },
57 { OPT_MASK(16), "PropagateConst" },
58 { OPT_MASK(17), "MinMaxOpt" },
59 { OPT_MASK(18), "SeekScan" },
60 { OPT_MASK(19), "OmitOrderBy" },
61 { OPT_MASK(20), "BloomFilter" },
62 { OPT_MASK(21), "DevTest" },
63 { OPT_MASK(22), "BalancedMerge" },
64 { OPT_MASK(23), "ReleaseReg" },
65 { OPT_MASK(24), "FlttnUnionAll" },
66 { OPT_MASK(25), "IndexedExpr" },
67 { OPT_MASK(26), "Coroutines" },
68 { OPT_MASK(27), "NullUnusedCols" },
69 { OPT_MASK(28), "OnePass" },
70 { OPT_MASK(29), "OrderBySubq" },
71 { OPT_MASK(29), "OrderBySubquery" }, /* Alias for prior */
72 { OPT_MASK(30), "StarQuery" },
73 { OPT_MASK(31), "ExistsToJoin" },
74 { OPT_MASK(32), "UnionLimit" },
75 { OPT_MASK(33), "HavingToWhere" },
76 /* Special names */
77 { 0xffffffffffffffffULL, "All" },
78 { 0x0000000000000000ULL, "None" },
79};
80
81/*
82** Given a symbolic name, try to compute the corresponding mask.
83**
84** The return value is:
85**
86** SQLITE_OK Successful match
87** SQLITE_NOTFOUND No match
88** SQLITE_MISUSE Bad arguments
89*/
90int sqlite3_optimization_mask(const char *zName, sqlite3_uint64 *pMask){
91 unsigned int i;
92 if( zName==0 || pMask==0 ){ return SQLITE_MISUSE; }
93 for(i=0; i<sizeof(aOpt)/sizeof(aOpt[0]); i++){
94 if( sqlite3_stricmp(zName, aOpt[i].zName)==0 ){
95 *pMask = aOpt[i].uMask;
96 return SQLITE_OK;
97 }
98 }
99 *pMask = 0;
100 return SQLITE_NOTFOUND;
101}
102
103/*
104** Given a bitmap, return the canonical symbolic name. Return 0 for
105** a bitmap input of 0 or a bitmap value that matches nothing.
106*/
107const char *sqlite3_optimization_name(sqlite3_uint64 mask){
108 unsigned int i;
109 for(i=0; i<sizeof(aOpt)/sizeof(aOpt[0]); i++){
110 if( aOpt[i].uMask==mask ){ return aOpt[i].zName; }
111 }
112 return 0;
113}