github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/interlock/reload_expr_pushdown_blacklist.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 interlock
    15  
    16  import (
    17  	"context"
    18  	"strings"
    19  
    20  	"github.com/whtcorpsinc/BerolinaSQL/ast"
    21  	"github.com/whtcorpsinc/milevadb/ekv"
    22  	"github.com/whtcorpsinc/milevadb/memex"
    23  	"github.com/whtcorpsinc/milevadb/soliton/chunk"
    24  	"github.com/whtcorpsinc/milevadb/soliton/sqlexec"
    25  	"github.com/whtcorpsinc/milevadb/stochastikctx"
    26  )
    27  
    28  // ReloadExprPushdownBlacklistInterDirc indicates ReloadExprPushdownBlacklist interlock.
    29  type ReloadExprPushdownBlacklistInterDirc struct {
    30  	baseInterlockingDirectorate
    31  }
    32  
    33  // Next implements the InterlockingDirectorate Next interface.
    34  func (e *ReloadExprPushdownBlacklistInterDirc) Next(ctx context.Context, _ *chunk.Chunk) error {
    35  	return LoadExprPushdownBlacklist(e.ctx)
    36  }
    37  
    38  // LoadExprPushdownBlacklist loads the latest data from causet allegrosql.expr_pushdown_blacklist.
    39  func LoadExprPushdownBlacklist(ctx stochastikctx.Context) (err error) {
    40  	allegrosql := "select HIGH_PRIORITY name, store_type from allegrosql.expr_pushdown_blacklist"
    41  	rows, _, err := ctx.(sqlexec.RestrictedALLEGROSQLInterlockingDirectorate).InterDircRestrictedALLEGROSQL(allegrosql)
    42  	if err != nil {
    43  		return err
    44  	}
    45  	newBlocklist := make(map[string]uint32, len(rows))
    46  	for _, event := range rows {
    47  		name := strings.ToLower(event.GetString(0))
    48  		storeTypeString := strings.ToLower(event.GetString(1))
    49  		if alias, ok := funcName2Alias[name]; ok {
    50  			name = alias
    51  		}
    52  		var value uint32 = 0
    53  		if val, ok := newBlocklist[name]; ok {
    54  			value = val
    55  		}
    56  		storeTypes := strings.Split(storeTypeString, ",")
    57  		for _, typeString := range storeTypes {
    58  			if typeString == ekv.MilevaDB.Name() {
    59  				value |= 1 << ekv.MilevaDB
    60  			} else if typeString == ekv.TiFlash.Name() {
    61  				value |= 1 << ekv.TiFlash
    62  			} else if typeString == ekv.EinsteinDB.Name() {
    63  				value |= 1 << ekv.EinsteinDB
    64  			}
    65  		}
    66  		newBlocklist[name] = value
    67  	}
    68  	memex.DefaultExprPushDownBlacklist.CausetStore(newBlocklist)
    69  	return nil
    70  }
    71  
    72  // funcName2Alias indicates map of the origin function name to the name used in MilevaDB.
    73  var funcName2Alias = map[string]string{
    74  	"and":                        ast.LogicAnd,
    75  	"cast":                       ast.Cast,
    76  	"<<":                         ast.LeftShift,
    77  	">>":                         ast.RightShift,
    78  	"or":                         ast.LogicOr,
    79  	">=":                         ast.GE,
    80  	"<=":                         ast.LE,
    81  	"=":                          ast.EQ,
    82  	"!=":                         ast.NE,
    83  	"<>":                         ast.NE,
    84  	"<":                          ast.LT,
    85  	">":                          ast.GT,
    86  	"+":                          ast.Plus,
    87  	"-":                          ast.Minus,
    88  	"&&":                         ast.And,
    89  	"||":                         ast.Or,
    90  	"%":                          ast.Mod,
    91  	"xor_bit":                    ast.Xor,
    92  	"/":                          ast.Div,
    93  	"*":                          ast.Mul,
    94  	"!":                          ast.UnaryNot,
    95  	"~":                          ast.BitNeg,
    96  	"div":                        ast.IntDiv,
    97  	"xor_logic":                  ast.LogicXor, // Avoid name conflict with "xor_bit".,
    98  	"<=>":                        ast.NullEQ,
    99  	"+_unary":                    ast.UnaryPlus, // Avoid name conflict with `plus`.,
   100  	"-_unary":                    ast.UnaryMinus,
   101  	"in":                         ast.In,
   102  	"like":                       ast.Like,
   103  	"case":                       ast.Case,
   104  	"regexp":                     ast.Regexp,
   105  	"is null":                    ast.IsNull,
   106  	"is true":                    ast.IsTruthWithoutNull,
   107  	"is false":                   ast.IsFalsity,
   108  	"values":                     ast.Values,
   109  	"bit_count":                  ast.BitCount,
   110  	"coalesce":                   ast.Coalesce,
   111  	"greatest":                   ast.Greatest,
   112  	"least":                      ast.Least,
   113  	"interval":                   ast.Interval,
   114  	"abs":                        ast.Abs,
   115  	"acos":                       ast.Acos,
   116  	"asin":                       ast.Asin,
   117  	"atan":                       ast.Atan,
   118  	"atan2":                      ast.Atan2,
   119  	"ceil":                       ast.Ceil,
   120  	"ceiling":                    ast.Ceiling,
   121  	"conv":                       ast.Conv,
   122  	"cos":                        ast.Cos,
   123  	"cot":                        ast.Cot,
   124  	"crc32":                      ast.CRC32,
   125  	"degrees":                    ast.Degrees,
   126  	"exp":                        ast.Exp,
   127  	"floor":                      ast.Floor,
   128  	"ln":                         ast.Ln,
   129  	"log":                        ast.Log,
   130  	"log2":                       ast.Log2,
   131  	"log10":                      ast.Log10,
   132  	"pi":                         ast.PI,
   133  	"pow":                        ast.Pow,
   134  	"power":                      ast.Power,
   135  	"radians":                    ast.Radians,
   136  	"rand":                       ast.Rand,
   137  	"round":                      ast.Round,
   138  	"sign":                       ast.Sign,
   139  	"sin":                        ast.Sin,
   140  	"sqrt":                       ast.Sqrt,
   141  	"tan":                        ast.Tan,
   142  	"truncate":                   ast.Truncate,
   143  	"adddate":                    ast.AddDate,
   144  	"addtime":                    ast.AddTime,
   145  	"convert_tz":                 ast.ConvertTz,
   146  	"curdate":                    ast.Curdate,
   147  	"current_date":               ast.CurrentDate,
   148  	"current_time":               ast.CurrentTime,
   149  	"current_timestamp":          ast.CurrentTimestamp,
   150  	"curtime":                    ast.Curtime,
   151  	"date":                       ast.Date,
   152  	"date_add":                   ast.DateAdd,
   153  	"date_format":                ast.DateFormat,
   154  	"date_sub":                   ast.DateSub,
   155  	"datediff":                   ast.DateDiff,
   156  	"day":                        ast.Day,
   157  	"dayname":                    ast.DayName,
   158  	"dayofmonth":                 ast.DayOfMonth,
   159  	"dayofweek":                  ast.DayOfWeek,
   160  	"dayofyear":                  ast.DayOfYear,
   161  	"extract":                    ast.Extract,
   162  	"from_days":                  ast.FromDays,
   163  	"from_unixtime":              ast.FromUnixTime,
   164  	"get_format":                 ast.GetFormat,
   165  	"hour":                       ast.Hour,
   166  	"localtime":                  ast.LocalTime,
   167  	"localtimestamp":             ast.LocalTimestamp,
   168  	"makedate":                   ast.MakeDate,
   169  	"maketime":                   ast.MakeTime,
   170  	"microsecond":                ast.MicroSecond,
   171  	"minute":                     ast.Minute,
   172  	"month":                      ast.Month,
   173  	"monthname":                  ast.MonthName,
   174  	"now":                        ast.Now,
   175  	"period_add":                 ast.PeriodAdd,
   176  	"period_diff":                ast.PeriodDiff,
   177  	"quarter":                    ast.Quarter,
   178  	"sec_to_time":                ast.SecToTime,
   179  	"second":                     ast.Second,
   180  	"str_to_date":                ast.StrToDate,
   181  	"subdate":                    ast.SubDate,
   182  	"subtime":                    ast.SubTime,
   183  	"sysdate":                    ast.Sysdate,
   184  	"time":                       ast.Time,
   185  	"time_format":                ast.TimeFormat,
   186  	"time_to_sec":                ast.TimeToSec,
   187  	"timediff":                   ast.TimeDiff,
   188  	"timestamp":                  ast.Timestamp,
   189  	"timestampadd":               ast.TimestampAdd,
   190  	"timestamFIDeliff":           ast.TimestamFIDeliff,
   191  	"to_days":                    ast.ToDays,
   192  	"to_seconds":                 ast.ToSeconds,
   193  	"unix_timestamp":             ast.UnixTimestamp,
   194  	"utc_date":                   ast.UTCDate,
   195  	"utc_time":                   ast.UTCTime,
   196  	"utc_timestamp":              ast.UTCTimestamp,
   197  	"week":                       ast.Week,
   198  	"weekday":                    ast.Weekday,
   199  	"weekofyear":                 ast.WeekOfYear,
   200  	"year":                       ast.Year,
   201  	"yearweek":                   ast.YearWeek,
   202  	"last_day":                   ast.LastDay,
   203  	"ascii":                      ast.ASCII,
   204  	"bin":                        ast.Bin,
   205  	"concat":                     ast.Concat,
   206  	"concat_ws":                  ast.ConcatWS,
   207  	"convert":                    ast.Convert,
   208  	"elt":                        ast.Elt,
   209  	"export_set":                 ast.ExportSet,
   210  	"field":                      ast.Field,
   211  	"format":                     ast.Format,
   212  	"from_base64":                ast.FromBase64,
   213  	"insert_func":                ast.InsertFunc,
   214  	"instr":                      ast.Instr,
   215  	"lcase":                      ast.Lcase,
   216  	"left":                       ast.Left,
   217  	"length":                     ast.Length,
   218  	"load_file":                  ast.LoadFile,
   219  	"locate":                     ast.Locate,
   220  	"lower":                      ast.Lower,
   221  	"lpad":                       ast.Lpad,
   222  	"ltrim":                      ast.LTrim,
   223  	"make_set":                   ast.MakeSet,
   224  	"mid":                        ast.Mid,
   225  	"oct":                        ast.Oct,
   226  	"octet_length":               ast.OctetLength,
   227  	"ord":                        ast.Ord,
   228  	"position":                   ast.Position,
   229  	"quote":                      ast.Quote,
   230  	"repeat":                     ast.Repeat,
   231  	"replace":                    ast.Replace,
   232  	"reverse":                    ast.Reverse,
   233  	"right":                      ast.Right,
   234  	"rtrim":                      ast.RTrim,
   235  	"space":                      ast.Space,
   236  	"strcmp":                     ast.Strcmp,
   237  	"substring":                  ast.Substring,
   238  	"substr":                     ast.Substr,
   239  	"substring_index":            ast.SubstringIndex,
   240  	"to_base64":                  ast.ToBase64,
   241  	"trim":                       ast.Trim,
   242  	"upper":                      ast.Upper,
   243  	"ucase":                      ast.Ucase,
   244  	"hex":                        ast.Hex,
   245  	"unhex":                      ast.Unhex,
   246  	"rpad":                       ast.Rpad,
   247  	"bit_length":                 ast.BitLength,
   248  	"char_func":                  ast.CharFunc,
   249  	"char_length":                ast.CharLength,
   250  	"character_length":           ast.CharacterLength,
   251  	"find_in_set":                ast.FindInSet,
   252  	"benchmark":                  ast.Benchmark,
   253  	"charset":                    ast.Charset,
   254  	"coercibility":               ast.Coercibility,
   255  	"defCauslation":              ast.DefCauslation,
   256  	"connection_id":              ast.ConnectionID,
   257  	"current_user":               ast.CurrentUser,
   258  	"current_role":               ast.CurrentRole,
   259  	"database":                   ast.Database,
   260  	"found_rows":                 ast.FoundEvents,
   261  	"last_insert_id":             ast.LastInsertId,
   262  	"row_count":                  ast.EventCount,
   263  	"schemaReplicant":            ast.Schema,
   264  	"stochastik_user":            ast.StochastikUser,
   265  	"system_user":                ast.SystemUser,
   266  	"user":                       ast.User,
   267  	"if":                         ast.If,
   268  	"ifnull":                     ast.Ifnull,
   269  	"nullif":                     ast.Nullif,
   270  	"any_value":                  ast.AnyValue,
   271  	"default_func":               ast.DefaultFunc,
   272  	"inet_aton":                  ast.InetAton,
   273  	"inet_ntoa":                  ast.InetNtoa,
   274  	"inet6_aton":                 ast.Inet6Aton,
   275  	"inet6_ntoa":                 ast.Inet6Ntoa,
   276  	"is_free_lock":               ast.IsFreeLock,
   277  	"is_ipv4":                    ast.IsIPv4,
   278  	"is_ipv4_compat":             ast.IsIPv4Compat,
   279  	"is_ipv4_mapped":             ast.IsIPv4Mapped,
   280  	"is_ipv6":                    ast.IsIPv6,
   281  	"is_used_lock":               ast.IsUsedLock,
   282  	"master_pos_wait":            ast.MasterPosWait,
   283  	"name_const":                 ast.NameConst,
   284  	"release_all_locks":          ast.ReleaseAllLocks,
   285  	"sleep":                      ast.Sleep,
   286  	"uuid":                       ast.UUID,
   287  	"uuid_short":                 ast.UUIDShort,
   288  	"get_lock":                   ast.GetLock,
   289  	"release_lock":               ast.ReleaseLock,
   290  	"aes_decrypt":                ast.AesDecrypt,
   291  	"aes_encrypt":                ast.AesEncrypt,
   292  	"compress":                   ast.Compress,
   293  	"decode":                     ast.Decode,
   294  	"des_decrypt":                ast.DesDecrypt,
   295  	"des_encrypt":                ast.DesEncrypt,
   296  	"encode":                     ast.Encode,
   297  	"encrypt":                    ast.Encrypt,
   298  	"md5":                        ast.MD5,
   299  	"old_password":               ast.OldPassword,
   300  	"password_func":              ast.PasswordFunc,
   301  	"random_bytes":               ast.RandomBytes,
   302  	"sha1":                       ast.SHA1,
   303  	"sha":                        ast.SHA,
   304  	"sha2":                       ast.SHA2,
   305  	"uncompress":                 ast.Uncompress,
   306  	"uncompressed_length":        ast.UncompressedLength,
   307  	"validate_password_strength": ast.ValidatePasswordStrength,
   308  	"json_type":                  ast.JSONType,
   309  	"json_extract":               ast.JSONExtract,
   310  	"json_unquote":               ast.JSONUnquote,
   311  	"json_array":                 ast.JSONArray,
   312  	"json_object":                ast.JSONObject,
   313  	"json_merge":                 ast.JSONMerge,
   314  	"json_set":                   ast.JSONSet,
   315  	"json_insert":                ast.JSONInsert,
   316  	"json_replace":               ast.JSONReplace,
   317  	"json_remove":                ast.JSONRemove,
   318  	"json_contains":              ast.JSONContains,
   319  	"json_contains_path":         ast.JSONContainsPath,
   320  	"json_valid":                 ast.JSONValid,
   321  	"json_array_append":          ast.JSONArrayAppend,
   322  	"json_array_insert":          ast.JSONArrayInsert,
   323  	"json_merge_patch":           ast.JSONMergePatch,
   324  	"json_merge_preserve":        ast.JSONMergePreserve,
   325  	"json_pretty":                ast.JSONPretty,
   326  	"json_quote":                 ast.JSONQuote,
   327  	"json_search":                ast.JSONSearch,
   328  	"json_storage_size":          ast.JSONStorageSize,
   329  	"json_depth":                 ast.JSONDepth,
   330  	"json_keys":                  ast.JSONKeys,
   331  	"json_length":                ast.JSONLength,
   332  }