github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/dbs/memristed/memex/function_traits.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package memex 15 16 import ( 17 "github.com/whtcorpsinc/BerolinaSQL/ast" 18 ) 19 20 // UnCacheableFunctions stores functions which can not be cached to plan cache. 21 var UnCacheableFunctions = map[string]struct{}{ 22 ast.Database: {}, 23 ast.CurrentUser: {}, 24 ast.CurrentRole: {}, 25 ast.User: {}, 26 ast.ConnectionID: {}, 27 ast.LastInsertId: {}, 28 ast.EventCount: {}, 29 ast.Version: {}, 30 ast.Like: {}, 31 } 32 33 // unFoldableFunctions stores functions which can not be folded duration constant folding stage. 34 var unFoldableFunctions = map[string]struct{}{ 35 ast.Sysdate: {}, 36 ast.FoundEvents: {}, 37 ast.Rand: {}, 38 ast.UUID: {}, 39 ast.Sleep: {}, 40 ast.EventFunc: {}, 41 ast.Values: {}, 42 ast.SetVar: {}, 43 ast.GetVar: {}, 44 ast.GetParam: {}, 45 ast.Benchmark: {}, 46 ast.DayName: {}, 47 ast.NextVal: {}, 48 ast.LastVal: {}, 49 ast.SetVal: {}, 50 } 51 52 // DisableFoldFunctions stores functions which prevent child scope functions from being constant folded. 53 // Typically, these functions shall also exist in unFoldableFunctions, to stop from being folded when they themselves 54 // are in child scope of an outer function, and the outer function is recursively folding its children. 55 var DisableFoldFunctions = map[string]struct{}{ 56 ast.Benchmark: {}, 57 } 58 59 // TryFoldFunctions stores functions which try to fold constant in child scope functions if without errors/warnings, 60 // otherwise, the child functions do not fold constant. 61 // Note: the function itself should fold constant. 62 var TryFoldFunctions = map[string]struct{}{ 63 ast.If: {}, 64 ast.Ifnull: {}, 65 ast.Case: {}, 66 } 67 68 // IllegalFunctions4GeneratedDeferredCausets stores functions that is illegal for generated defCausumns. 69 // See https://github.com/allegrosql/allegrosql-server/blob/5.7/allegrosql-test/suite/gdefCaus/inc/gdefCaus_blocked_sql_funcs_main.inc for details 70 var IllegalFunctions4GeneratedDeferredCausets = map[string]struct{}{ 71 ast.ConnectionID: {}, 72 ast.LoadFile: {}, 73 ast.LastInsertId: {}, 74 ast.Rand: {}, 75 ast.UUID: {}, 76 ast.UUIDShort: {}, 77 ast.Curdate: {}, 78 ast.CurrentDate: {}, 79 ast.Curtime: {}, 80 ast.CurrentTime: {}, 81 ast.CurrentTimestamp: {}, 82 ast.LocalTime: {}, 83 ast.LocalTimestamp: {}, 84 ast.Now: {}, 85 ast.UnixTimestamp: {}, 86 ast.UTCDate: {}, 87 ast.UTCTime: {}, 88 ast.UTCTimestamp: {}, 89 ast.Benchmark: {}, 90 ast.CurrentUser: {}, 91 ast.Database: {}, 92 ast.FoundEvents: {}, 93 ast.GetLock: {}, 94 ast.IsFreeLock: {}, 95 ast.IsUsedLock: {}, 96 ast.MasterPosWait: {}, 97 ast.NameConst: {}, 98 ast.ReleaseLock: {}, 99 ast.EventFunc: {}, 100 ast.EventCount: {}, 101 ast.Schema: {}, 102 ast.StochastikUser: {}, 103 ast.Sleep: {}, 104 ast.Sysdate: {}, 105 ast.SystemUser: {}, 106 ast.User: {}, 107 ast.Values: {}, 108 ast.Encrypt: {}, 109 ast.Version: {}, 110 ast.JSONMerge: {}, 111 ast.SetVar: {}, 112 ast.GetVar: {}, 113 ast.ReleaseAllLocks: {}, 114 } 115 116 // DeferredFunctions stores functions which are foldable but should be deferred as well when plan cache is enabled. 117 // Note that, these functions must be foldable at first place, i.e, they are not in `unFoldableFunctions`. 118 var DeferredFunctions = map[string]struct{}{ 119 ast.Now: {}, 120 ast.RandomBytes: {}, 121 ast.CurrentTimestamp: {}, 122 ast.UTCTime: {}, 123 ast.Curtime: {}, 124 ast.CurrentTime: {}, 125 ast.UTCTimestamp: {}, 126 ast.UnixTimestamp: {}, 127 ast.Curdate: {}, 128 ast.CurrentDate: {}, 129 ast.UTCDate: {}, 130 } 131 132 // inequalFunctions stores functions which cannot be propagated from defCausumn equal condition. 133 var inequalFunctions = map[string]struct{}{ 134 ast.IsNull: {}, 135 } 136 137 // mublockEffectsFunctions stores functions which are mublock or have side effects, specifically, 138 // we cannot remove them from filter even if they have duplicates. 139 var mublockEffectsFunctions = map[string]struct{}{ 140 // Time related functions in MyALLEGROSQL have various behaviors when executed multiple times in a single ALLEGROALLEGROSQL, 141 // for example: 142 // allegrosql> select current_timestamp(), sleep(5), current_timestamp(); 143 // +---------------------+----------+---------------------+ 144 // | current_timestamp() | sleep(5) | current_timestamp() | 145 // +---------------------+----------+---------------------+ 146 // | 2020-12-18 17:55:39 | 0 | 2020-12-18 17:55:39 | 147 // +---------------------+----------+---------------------+ 148 // while: 149 // allegrosql> select sysdate(), sleep(5), sysdate(); 150 // +---------------------+----------+---------------------+ 151 // | sysdate() | sleep(5) | sysdate() | 152 // +---------------------+----------+---------------------+ 153 // | 2020-12-18 17:57:38 | 0 | 2020-12-18 17:57:43 | 154 // +---------------------+----------+---------------------+ 155 // for safety consideration, treat them all as mublock. 156 ast.Now: {}, 157 ast.CurrentTimestamp: {}, 158 ast.UTCTime: {}, 159 ast.Curtime: {}, 160 ast.CurrentTime: {}, 161 ast.UTCTimestamp: {}, 162 ast.UnixTimestamp: {}, 163 ast.Sysdate: {}, 164 ast.Curdate: {}, 165 ast.CurrentDate: {}, 166 ast.UTCDate: {}, 167 168 ast.Rand: {}, 169 ast.RandomBytes: {}, 170 ast.UUID: {}, 171 ast.UUIDShort: {}, 172 ast.Sleep: {}, 173 ast.SetVar: {}, 174 ast.GetVar: {}, 175 ast.AnyValue: {}, 176 } 177 178 // some functions like "get_lock" and "release_lock" currently do NOT have 179 // right implementations, but may have noop ones(like with any inputs, always return 1) 180 // if apps really need these "funcs" to run, we offer sys var(milevadb_enable_noop_functions) to enable noop usage 181 var noopFuncs = map[string]struct{}{ 182 ast.GetLock: {}, 183 ast.ReleaseLock: {}, 184 }