github.com/matrixorigin/matrixone@v1.2.0/proto/plan.proto (about) 1 /* 2 * Copyright 2021 Matrix Origin 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 syntax = "proto3"; 18 package plan; 19 20 import "github.com/gogo/protobuf/gogoproto/gogo.proto"; 21 import "lock.proto"; 22 import "timestamp.proto"; 23 24 option go_package = "github.com/matrixorigin/matrixone/pkg/pb/plan"; 25 option (gogoproto.sizer_all) = false; 26 option (gogoproto.protosizer_all) = true; 27 28 message Type { 29 int32 id = 1; 30 bool notNullable = 2; 31 bool auto_incr = 3; 32 int32 width = 4; 33 int32 scale = 5; 34 string table = 6; 35 string enumvalues = 7; 36 }; 37 38 message msgHeader { 39 int32 msg_tag = 1; 40 int32 msg_type =2; 41 }; 42 43 // Literal: if a literal value can be reprensented by int64 or 44 // double, use that, otherwise store a string representation. 45 message Literal { 46 bool isnull = 1; 47 oneof value { 48 int32 i8val = 2; // pb have no int8 49 int32 i16val = 3; // pb have no int16 50 int32 i32val = 4; 51 int64 i64val = 5; 52 uint32 u8val = 6; // pb have no uint8 53 uint32 u16val = 7; // pb have no uint16 54 uint32 u32val = 8; 55 uint64 u64val = 9; 56 double dval = 10; 57 string sval = 11; 58 bool bval = 12; 59 float fval = 13; 60 int32 dateval = 14; 61 int64 timeval = 15; 62 int64 datetimeval = 16; 63 decimal64 decimal64val = 17; 64 decimal128 decimal128val = 18; 65 int64 timestampval = 19; 66 string jsonval = 20; 67 bool defaultval = 21; 68 bool updateVal = 22; 69 uint32 enumVal = 23; // pb have no uint32 70 } 71 bool isBin = 24; 72 Expr src = 25; // if generated by replacing an existing expr 73 } 74 75 // Bounded param for prepared statement. User fill on execution. 76 message ParamRef { 77 int32 pos = 1; 78 } 79 80 // Session variable ref, compiler should fold. 81 message VarRef { 82 string name = 1; 83 bool system = 2; 84 bool global = 3; 85 } 86 87 // Reference a column in the proj list of a node. 88 message ColRef { 89 int32 rel_pos = 1; 90 int32 col_pos = 2; 91 string name = 3; 92 string tbl_name = 4; 93 string db_name = 5; 94 } 95 96 // Reference a column by its internal table id and column id 97 message RawColRef { 98 uint64 tbl_id = 1; 99 uint64 col_id = 2; 100 } 101 102 // Reference a correlated column in the proj list of a node. 103 message CorrColRef { 104 int32 rel_pos = 1; 105 int32 col_pos = 2; 106 int32 depth = 3; 107 } 108 109 // ExprList is a type of Expr 110 message ExprList { 111 repeated Expr list = 1; 112 } 113 114 message MaxValue { 115 string value = 1; 116 } 117 118 // TargetType used in cast function as target type 119 message TargetType { 120 } 121 122 // Reference a subquery 123 message SubqueryRef { 124 enum Type { 125 SCALAR = 0; 126 EXISTS = 1; 127 NOT_EXISTS = 2; 128 IN = 3; 129 NOT_IN = 4; 130 ANY = 5; 131 ALL = 6; 132 } 133 134 Type typ = 1; 135 int32 node_id = 2; 136 string op = 3; 137 Expr child = 4; 138 int32 row_size = 5; 139 } 140 141 // Object ref, reference a object in database, 4 part name. 142 message ObjectRef { 143 int64 server = 1; 144 int64 db = 2; 145 int64 schema = 3; 146 int64 obj = 4; 147 string server_name = 5; 148 string db_name = 6; 149 string schema_name = 7; 150 string obj_name = 8; 151 string subscription_name = 9; 152 PubInfo pub_info = 10; 153 } 154 155 message PubInfo { 156 int32 tenant_id = 1; 157 } 158 159 message SubscriptionMeta{ 160 string name = 1; // pubName 161 int32 account_id = 2; // pubAccountID 162 string db_name = 3; // pubDbName 163 string account_name = 4;// pubAccountName 164 string sub_name = 5; // subName(subscription side db name) 165 } 166 167 message Function { 168 // Function flags 169 enum FuncFlag { 170 NONE = 0; 171 // Internal function is generated by system, cannot 172 // by called by user. 173 INTERNAL = 1; 174 175 // Function, by default is immutable. 176 STABLE = 2; 177 VOLATILE = 4; 178 179 // Nulls 180 STRICT = 8; 181 PRODUCE_NULL = 16; 182 PRODUCE_NO_NULL = 32; 183 184 // Vararg, all trailing args must be of the same type. 185 VARARG = 64; 186 187 // Window and Agg 188 AGG = 128; 189 WIN_VALUE = 256; 190 WIN_ORDER = 512; 191 192 // Filter which can be applied on zonemaps 193 ZONEMAPPABLE = 1024; 194 } 195 196 ObjectRef func = 1; 197 repeated Expr args = 2; 198 } 199 200 message Expr { 201 Type typ = 1 [(gogoproto.nullable) = false]; 202 oneof expr { 203 Literal lit = 2; 204 ParamRef p = 3; 205 VarRef v = 4; 206 ColRef col = 5; 207 RawColRef raw = 6; 208 Function f = 7; 209 WindowSpec w = 8; 210 SubqueryRef sub = 9; 211 CorrColRef corr = 10; 212 TargetType t = 11; 213 ExprList list = 12; 214 MaxValue max = 13; 215 LiteralVec vec = 14; 216 } 217 218 int32 aux_id = 15; 219 double ndv = 16; 220 double selectivity = 17; 221 } 222 223 message LiteralVec { 224 int32 len = 1; 225 bytes data = 2; 226 } 227 228 enum CompressType { 229 None = 0; 230 Lz4 = 1; 231 } 232 233 message decimal64 { 234 int64 a = 1; 235 } 236 237 message decimal128 { 238 int64 a = 1; 239 int64 b = 2; 240 } 241 242 message ResultColDef { 243 repeated ColDef ResultCols = 1; 244 } 245 246 message ColDef { 247 uint64 col_id = 1; 248 string name = 2; 249 bool hidden = 3; 250 CompressType alg = 4; 251 Type typ = 5 [(gogoproto.nullable) = false]; 252 bool not_null = 6; 253 Default default = 7; 254 string comment = 8; 255 OnUpdate on_update = 9; 256 bool low_card = 10; 257 uint32 seqnum = 11; 258 259 // XXX: Deprecated and to be removed soon. 260 bool clusterBy = 12; 261 bool primary = 13; 262 int32 pkidx = 14; 263 bool headers = 15; 264 string header = 16; 265 266 string tbl_name = 17; 267 string db_name = 18; 268 } 269 270 message Default { 271 Expr expr = 1; 272 string origin_string = 2; 273 274 // XXX: Deprecated and to be removed soon. 275 bool null_ability = 3; 276 } 277 278 message OnUpdate { 279 Expr expr = 1; 280 string origin_string = 2; 281 } 282 283 message IndexOption { 284 bool create_extra_table = 1; 285 } 286 287 message PrimaryKeyDef { 288 // currently not used 289 repeated uint64 cols = 1; 290 // currently not used 291 uint64 pkey_col_id = 2; 292 // currently not used 293 IndexOption option = 3; 294 295 // Composed primary key column name: __mo_cpkey 296 string pkey_col_name = 4; 297 // XXX: Deprecated and to be removed soon. 298 repeated string names = 5; 299 // Composite primary key column definition 300 ColDef comp_pkey_col = 6; 301 } 302 303 message IndexDef { 304 // Generate UUID for each index, currently not used 305 string idx_id = 1; 306 string index_name = 2; 307 // The constituent columns of the index 308 repeated string parts = 3; 309 bool unique = 4; 310 string index_table_name = 5; 311 bool table_exist = 6; 312 string comment = 7; 313 bool visible = 8; 314 // currently not used 315 IndexOption option = 9; 316 string index_algo = 10; 317 string index_algo_table_type = 11; 318 string index_algo_params=12; 319 } 320 321 322 message ForeignKeyDef { 323 enum RefAction { 324 RESTRICT = 0; 325 CASCADE = 1; 326 SET_NULL = 2; 327 SET_DEFAULT = 3; 328 NO_ACTION = 4; 329 } 330 331 string name = 1; 332 repeated uint64 cols = 2; 333 // Foreign key parent table Id 334 uint64 foreign_tbl = 3; 335 // Foreign key parent table dependent column colids 336 repeated uint64 foreign_cols = 4; 337 RefAction on_delete = 5; 338 RefAction on_update = 6; 339 } 340 341 message CheckDef { 342 string name = 1; 343 // Name for anonymous constraints, __mo_chk_[INDEX_ID] 344 Expr check = 2; 345 } 346 347 message ClusterByDef { 348 // XXX: Deprecated and to be removed soon. 349 string name = 1; 350 // Composite cluster by column definition 351 ColDef comp_cbkey_col = 2; 352 } 353 354 message PropertyDef { 355 string key = 1; 356 string value = 2; 357 } 358 359 message Property { 360 string key = 1; 361 string value = 2; 362 } 363 364 message PropertiesDef { 365 repeated Property properties = 1; 366 } 367 368 369 enum PartitionType { 370 KEY = 0; 371 LINEAR_KEY = 1; 372 HASH = 2; 373 LINEAR_HASH = 3; 374 RANGE = 4; 375 RANGE_COLUMNS = 5; 376 LIST = 6; 377 LIST_COLUMNS = 7; 378 } 379 380 message PartitionByDef { 381 PartitionType type = 1; 382 PartitionExpr partition_expr = 2; 383 Expr partition_expression = 3; 384 PartitionColumns partition_columns = 4; 385 uint64 partitionNum = 5; 386 repeated PartitionItem partitions = 6; 387 int64 algorithm = 7; 388 bool is_sub_partition = 8; 389 string partition_msg = 9; 390 repeated string partition_table_names = 10; 391 } 392 393 message PartitionExpr { 394 Expr expr = 1; 395 string expr_str = 2; 396 // string expr_fmt_str = 3; 397 } 398 399 message PartitionColumns { 400 repeated Expr columns = 1; 401 repeated string partition_columns = 2; 402 // repeated string partition_fmt_columns = 3; 403 } 404 405 message PartitionItem { 406 string partition_name = 1; 407 uint32 ordinal_position = 2; 408 string description = 3; 409 string comment = 4; 410 repeated Expr less_than = 5; 411 repeated Expr in_values = 6; 412 string partition_table_name = 7;// the table name of a partition 413 } 414 415 416 message ViewDef { 417 string view = 1; 418 } 419 420 message TableDef { 421 // XXX: Deprecated and to be removed soon. 422 message DefType { 423 oneof def { 424 PropertiesDef properties = 1; 425 } 426 } 427 428 uint64 tbl_id = 1; 429 string name = 2; 430 bool hidden = 3; 431 repeated ColDef cols = 4; 432 string table_type = 5; 433 string createsql = 6; 434 TableFunction tbl_func = 7; 435 uint32 version = 8; 436 437 PrimaryKeyDef pkey = 11; 438 repeated IndexDef indexes = 12; 439 repeated ForeignKeyDef fkeys = 13; 440 repeated uint64 ref_child_tbls = 14; 441 repeated CheckDef checks = 15; 442 443 PartitionByDef partition = 21; 444 ClusterByDef cluster_by = 22; 445 repeated PropertyDef props = 23; 446 ViewDef view_sql = 24; 447 448 // XXX: Deprecated and to be removed soon. 449 repeated DefType defs = 25; 450 map<string, int32> name2col_index = 26; 451 bool isLocked = 27; 452 TableLockType tableLockType = 28; 453 bool is_temporary = 29; 454 455 uint64 auto_incr_offset = 30; 456 bool is_dynamic = 31; 457 458 string db_name = 32; 459 } 460 461 message TableFunction{ 462 string name = 1; 463 bytes param = 2; 464 } 465 466 enum ShuffleType { 467 Hash = 0; 468 Range = 1; 469 } 470 471 enum ShuffleMethod { 472 Normal = 0; 473 Reuse = 1; 474 Reshuffle = 2; 475 } 476 477 enum ShuffleTypeForMultiCN { 478 Simple = 0; 479 Hybrid = 1; 480 } 481 482 message HashMapStats{ 483 // hashmap size for nodes which build a hashmap 484 double hashmap_size = 1; 485 bool hashOnPK = 2; 486 487 // for group by and join node with big hashmap, use shuffle 488 // shuffle on which column. choose a column with max ndv 489 bool shuffle = 3; 490 int32 shuffleColIdx = 4; 491 // shuffle type 492 ShuffleType shuffleType = 5; 493 ShuffleTypeForMultiCN shuffleTypeForMultiCN = 6; 494 // for range shuffle on integer column, need to know its min and max value 495 int64 shuffleColMin = 7; 496 int64 shuffleColMax = 8; 497 ShuffleMethod shuffleMethod = 9; 498 int64 nullcnt=10; 499 repeated double ranges = 11; 500 } 501 502 message Stats { 503 //for scan, number of blocks to read from S3 504 int32 block_num = 1; 505 //for scan, cost of reading from S3, basically the read lines 506 //for other nodes, it means the estimated cost of current node 507 double cost = 2; 508 //number of output lines 509 double outcnt = 3; 510 // average size of one row, currently not used 511 double rowsize = 4; 512 //for scan, this means total count of all table, before filtering 513 double table_cnt = 5; 514 //for scan, selectivity means outcnt divide total count 515 double selectivity = 6; 516 bool forceOneCN = 7; 517 518 HashMapStats hashmapStats = 8; 519 } 520 521 message RowsetExpr { 522 int32 row_pos = 1; 523 int32 pos = 2; 524 Expr expr = 3; 525 } 526 527 message ColData { 528 repeated RowsetExpr data = 1; 529 } 530 531 message RowsetData { 532 repeated ColData cols = 1; 533 int32 row_count = 2; 534 } 535 536 message OrderBySpec { 537 enum OrderByFlag { 538 INTERNAL = 0; 539 ASC = 1; 540 DESC = 2; 541 NULLS_FIRST = 4; 542 NULLS_LAST = 8; 543 UNIQUE = 16; 544 } 545 546 Expr expr = 1; 547 string collation = 2; 548 OrderByFlag flag = 3; 549 } 550 551 message WindowSpec { 552 Expr window_func = 1; 553 repeated Expr partition_by = 2; 554 repeated OrderBySpec order_by = 3; 555 FrameClause frame = 4; 556 string name = 5; 557 } 558 559 message SampleFuncSpec { 560 int32 Rows = 1; 561 double Percent = 2; 562 bool UsingRow = 3; 563 } 564 565 message FrameClause { 566 enum FrameType { 567 ROWS = 0; 568 RANGE = 1; 569 } 570 FrameType type = 1; 571 FrameBound start = 2; 572 FrameBound end = 3; 573 } 574 575 message FrameBound { 576 enum BoundType { 577 FOLLOWING = 0; 578 PRECEDING = 1; 579 CURRENT_ROW = 2; 580 } 581 BoundType type = 1; 582 bool unBounded = 2; 583 Expr val = 3; 584 } 585 586 message OnDuplicateKeyCtx { 587 repeated string attrs = 1; 588 int32 insert_col_count = 2; 589 repeated Expr unique_col_check_expr = 3; 590 repeated string unique_cols = 4; 591 repeated int32 on_duplicate_idx = 5; 592 map<string, Expr> on_duplicate_expr = 6; 593 bool is_ignore = 7; 594 string table_name = 8; 595 uint64 table_id = 9; 596 uint32 table_version = 10; 597 } 598 599 message InsertCtx { 600 ObjectRef ref = 1; 601 bool add_affected_rows = 2; 602 bool is_cluster_table = 3; 603 TableDef table_def = 4; 604 // Align array index with the partition number 605 repeated uint64 partition_table_ids = 5; 606 repeated string partition_table_names = 6; 607 int32 partition_idx = 7; 608 } 609 610 message ReplaceCtx { 611 ObjectRef ref = 1; 612 bool add_affected_rows = 2; 613 bool is_cluster_table = 3; 614 TableDef table_def = 4; 615 string delete_cond = 5; 616 // Align array index with the partition number 617 repeated uint64 partition_table_ids = 6; 618 repeated string partition_table_names = 7; 619 int32 partition_idx = 8; 620 } 621 622 message AnalyzeInfo { 623 int64 input_rows = 1; 624 int64 output_rows = 2; 625 int64 input_size = 3; 626 int64 output_size = 4; 627 int64 time_consumed = 5; 628 int64 memory_size = 6; 629 int64 wait_time_consumed = 7; 630 int64 diskIO = 8; 631 int64 s3IO_byte = 9; 632 int64 s3IO_input_count = 10; 633 int64 s3IO_output_count = 11; 634 int64 networkIO = 12; 635 int64 scanTime = 13; 636 int64 insertTime = 14; 637 repeated int64 time_consumed_array_major = 15; 638 repeated int64 time_consumed_array_minor = 16; 639 } 640 641 message PartitionPrune { 642 bool isPruned = 1; 643 repeated PartitionItem selected_partitions = 2; 644 } 645 646 message OriginTableMessageForFuzzy { 647 string ParentTableName = 1; 648 repeated ColDef ParentUniqueCols = 2; 649 } 650 651 message Node { 652 enum NodeType { 653 UNKNOWN = 0; 654 // Node Types 655 656 // Scans 657 VALUE_SCAN = 1; 658 TABLE_SCAN = 2; 659 FUNCTION_SCAN = 3; 660 EXTERNAL_SCAN = 4; 661 MATERIAL_SCAN = 5; 662 SOURCE_SCAN = 6; 663 664 // Proj, for convenience 665 PROJECT = 10; 666 // External function call (UDF) 667 EXTERNAL_FUNCTION = 11; 668 669 // Material, CTE, etc. 670 MATERIAL = 20; 671 RECURSIVE_CTE = 21; 672 SINK = 22; 673 SINK_SCAN = 23; 674 RECURSIVE_SCAN = 24; 675 676 // Proper Relational Operators 677 AGG = 30; 678 DISTINCT = 31; 679 FILTER = 32; 680 JOIN = 33; 681 SAMPLE = 34; 682 SORT = 35; 683 UNION = 36; 684 UNION_ALL = 37; 685 UNIQUE = 38; 686 WINDOW = 39; 687 688 // Physical tuple mover 689 BROADCAST = 40; 690 SPLIT = 41; 691 GATHER = 42; 692 693 // Misc 694 ASSERT = 50; 695 696 // 697 INSERT = 51; 698 DELETE = 52; 699 REPLACE = 53; 700 // 701 LOCK_OP = 54; 702 703 // 704 INTERSECT = 55; 705 INTERSECT_ALL = 56; 706 MINUS = 57; 707 MINUS_ALL = 58; 708 709 // 710 ON_DUPLICATE_KEY = 59; 711 PRE_INSERT = 60; 712 PRE_DELETE = 61; 713 // the node which build insert batch for hidden table(unique key) 714 PRE_INSERT_UK = 62; 715 PRE_INSERT_SK = 63; 716 // 717 TIME_WINDOW = 64; 718 FILL = 65; 719 PARTITION = 66; 720 FUZZY_FILTER = 67; 721 } 722 723 enum JoinType { 724 INNER = 0; 725 LEFT = 1; 726 RIGHT = 2; 727 OUTER = 3; 728 SEMI = 4; 729 ANTI = 5; 730 SINGLE = 6; 731 MARK = 7; 732 APPLY = 8; 733 INDEX = 9; 734 } 735 736 enum AggMode { 737 FULL = 0; 738 BOTTOM = 1; 739 TOP = 2; 740 } 741 742 enum FillType { 743 NONE = 0; 744 PREV = 1; 745 NEXT = 2; 746 NULL = 3; 747 VALUE = 4; 748 LINEAR = 5; 749 } 750 751 NodeType node_type = 1; 752 int32 node_id = 2; 753 Stats stats = 3; 754 repeated int32 children = 4; 755 756 // PROJECT 757 repeated Expr project_list = 5; 758 759 // JOIN 760 JoinType join_type = 6; 761 repeated Expr on_list = 7; 762 bool build_on_left = 8; 763 764 // FILTER 765 repeated Expr filter_list = 9; 766 767 // AGG 768 repeated Expr group_by = 10; 769 repeated Expr grouping_set = 11; 770 repeated Expr agg_list = 12; 771 772 // WINDOW 773 repeated Expr win_spec_list = 13; 774 775 // SORT 776 repeated OrderBySpec order_by = 14; 777 778 // LIMIT 779 Expr limit = 15; 780 Expr offset = 16; 781 782 TableDef table_def = 17; 783 ObjectRef obj_ref = 18; 784 ObjectRef parent_obj_ref = 19; 785 RowsetData rowset_data = 20; 786 787 string extra_options = 22; 788 DeleteCtx delete_ctx = 23; 789 790 repeated int32 binding_tags = 24; 791 792 AnalyzeInfo analyze_info = 25; 793 794 repeated Expr tbl_func_expr_list = 26; 795 796 ClusterTable cluster_table = 28; 797 bool not_cacheable = 29; 798 InsertCtx insert_ctx = 30; 799 ReplaceCtx replace_ctx = 31; 800 801 // used to connect two plans[steps] 802 repeated int32 source_step = 32; 803 804 PreDeleteCtx pre_delete_ctx = 33; 805 PreInsertCtx pre_insert_ctx = 34; 806 // build unique key batch before insert into hidden table which keep the unique key 807 PreInsertUkCtx pre_insert_uk_ctx = 35; 808 OnDuplicateKeyCtx on_duplicate_key = 36; 809 810 bool IsEnd = 37; 811 repeated LockTarget lock_targets = 38; 812 repeated Expr block_filter_list = 39; 813 814 // Runtime filters 815 repeated RuntimeFilterSpec runtime_filter_probe_list = 40; 816 repeated RuntimeFilterSpec runtime_filter_build_list = 41; 817 818 bytes uuid = 42; 819 bool recursive_sink = 43; 820 ExternScan extern_scan = 44; 821 PartitionPrune partition_prune = 45; 822 823 PreInsertUkCtx pre_insert_sk_ctx = 46; 824 Expr interval = 47; 825 Expr sliding = 48; 826 827 FillType fill_type = 49; 828 repeated Expr fill_val = 50; 829 830 // sample function related. 831 SampleFuncSpec sample_func = 51; 832 833 int32 window_idx = 52; 834 repeated Expr onUpdateExprs = 53; 835 OriginTableMessageForFuzzy fuzzymessage = 54; 836 837 //for message 838 repeated msgHeader send_msg_list = 55; 839 repeated msgHeader recv_msg_list = 56; 840 841 Snapshot scan_snapshot = 57; 842 } 843 844 // Snapshot Represents a snapshot of the database 845 message Snapshot { 846 // The timestamp of the snapshot 847 timestamp.Timestamp TS = 1; 848 // Tenant information for creating snapshots 849 SnapshotTenant tenant = 2; 850 } 851 852 // Tenant information for creating snapshots 853 message SnapshotTenant { 854 string tenantName = 1; 855 uint32 tenantID = 2; 856 } 857 858 859 message ExternScan { 860 int32 type = 1; 861 string data = 2; 862 string format = 3; 863 uint64 ignored_lines = 4; 864 bytes enclosed_by = 5; 865 string terminated = 6; 866 string json_type = 7; 867 bytes escaped_by = 8; 868 } 869 870 message LockTarget { 871 uint64 table_id = 1; 872 int32 primary_col_idx_in_bat = 2; 873 Type primary_col_typ = 3 [(gogoproto.nullable) = false]; 874 int32 refresh_ts_idx_in_bat = 4; 875 int32 filter_col_idx_in_bat = 5; 876 bool lock_table = 6; 877 bool is_partition_table = 7; 878 repeated uint64 partition_table_ids = 8; 879 bool block = 9; 880 lock.LockMode Mode = 10; 881 } 882 883 message PreInsertUkCtx { 884 // index of columns(parts of unique key) in pre batch 885 repeated int32 columns = 1; 886 int32 pk_column = 2; 887 Type pk_type = 3 [(gogoproto.nullable) = false]; 888 Type uk_type = 4 [(gogoproto.nullable) = false]; 889 } 890 891 message PreDeleteCtx { 892 //the indexes of row_id&pk column in the batch 893 repeated int32 idx = 1; 894 } 895 896 message PreInsertCtx { 897 ObjectRef ref = 1; 898 TableDef table_def = 2; 899 bool has_auto_col = 3; 900 bool is_update = 4; 901 } 902 903 message RuntimeFilterSpec { 904 int32 tag = 1; 905 bool match_prefix = 2; 906 int32 upper_limit = 3; 907 Expr expr = 4; 908 bool handled = 5; 909 } 910 911 message IdList { 912 repeated int64 list = 1; 913 } 914 915 message ColPosMap { 916 map<string, int32> map = 1; 917 } 918 919 message DeleteCtx { 920 bool can_truncate = 1; 921 ObjectRef ref = 2; 922 int32 row_id_idx = 3; 923 bool add_affected_rows = 4; 924 bool is_cluster_table = 5; 925 // Align array index with the partition number 926 repeated uint64 partition_table_ids = 6; 927 repeated string partition_table_names = 7; 928 int32 partition_idx = 8; 929 int32 primary_key_idx = 9; 930 TruncateTable truncate_table = 10; 931 TableDef table_def = 11; 932 } 933 934 message Query { 935 enum StatementType { 936 UNKNOWN = 0; 937 SELECT = 1; 938 INSERT = 2; 939 REPLACE = 3; 940 DELETE = 4; 941 UPDATE = 5; 942 MERGE = 6; 943 } 944 945 StatementType stmt_type = 1; 946 947 // A query may need to run in steps. This in theory is not 948 // necessary but often convenient and/or can be better optimized. 949 // For example, executing non correctlated scalar subquery first 950 // we can plug the value in the optmizer and the newly available 951 // value may generate better plan. 952 953 // Each step is simply a root node. Root node refers to other 954 // node as children and the whole step is a DAG. 955 repeated int32 steps = 2; 956 957 // All the nodes. It is OK to have dangle nodes, we only excute nodes 958 // reachable from step roots. 959 repeated Node nodes = 3; 960 961 // Bound Parameter for the query. 962 repeated Expr params = 4; 963 964 // return head 965 repeated string headings = 5; 966 967 // load Tag 968 bool loadTag = 6; 969 970 //detectSqls are sqls detect fk self refer constraint 971 repeated string detectSqls= 7; 972 } 973 974 message TransationControl { 975 enum TclType { 976 BEGIN = 0; 977 COMMIT = 1; 978 ROLLBACK = 2; 979 } 980 //TransationControl type 981 TclType tcl_type = 1; 982 oneof action { 983 TransationBegin begin = 2; 984 TransationCommit commit = 3; 985 TransationRollback rollback = 4; 986 } 987 } 988 989 message TransationBegin { 990 enum TransationMode { 991 NONE = 0; 992 READ_ONLY = 1; 993 READ_WRITE = 2; 994 } 995 TransationMode mode = 1; 996 } 997 998 enum TransationCompletionType { 999 CHAIN = 0; 1000 NO_CHAIN = 1; 1001 RELEASE = 2; 1002 } 1003 message TransationCommit { 1004 TransationCompletionType completion_type = 1; 1005 } 1006 message TransationRollback { 1007 TransationCompletionType completion_type = 1; 1008 } 1009 1010 message Plan { 1011 oneof plan { 1012 Query query = 1; 1013 TransationControl tcl = 2; 1014 DataDefinition ddl = 3; 1015 DataControl dcl = 4; 1016 } 1017 int32 try_run_times = 5; 1018 bool is_prepare = 6; 1019 } 1020 1021 message column{ 1022 repeated Expr column = 1; 1023 } 1024 1025 message DataControl { 1026 enum DclType { 1027 SET_VARIABLES = 0; 1028 GRANT = 1; 1029 REVOKE = 2; 1030 DENY = 3; 1031 PREPARE = 4; 1032 EXECUTE = 5; 1033 DEALLOCATE = 6; 1034 CREATE_ACCOUNT = 7; 1035 ALTER_ACCOUNT = 8; 1036 DROP_ACCOUNT = 9; 1037 } 1038 //DataDefinition type 1039 DclType dcl_type = 1; 1040 oneof control { 1041 SetVariables set_variables = 2; 1042 Prepare prepare = 3; 1043 Execute execute = 4; 1044 Deallocate deallocate = 5; 1045 OtherDCL other = 6; 1046 } 1047 } 1048 1049 message DataDefinition { 1050 enum DdlType { 1051 CREATE_DATABASE = 0; 1052 ALTER_DATABASE = 1; 1053 DROP_DATABASE = 2; 1054 CREATE_TABLE = 3; 1055 ALTER_TABLE = 4; 1056 DROP_TABLE = 5; 1057 CREATE_INDEX = 6; 1058 ALTER_INDEX = 7; 1059 DROP_INDEX = 8; 1060 TRUNCATE_TABLE = 9; 1061 CREATE_VIEW = 10; 1062 ALTER_VIEW = 11; 1063 DROP_VIEW = 12; 1064 SHOW_CREATEDATABASE = 13; 1065 SHOW_CREATETABLE = 14; 1066 SHOW_DATABASES = 15; 1067 SHOW_TABLES = 16; 1068 SHOW_COLUMNS = 17; 1069 SHOW_INDEX = 18; 1070 SHOW_VARIABLES = 19; 1071 SHOW_WARNINGS = 20; 1072 SHOW_ERRORS = 21; 1073 SHOW_STATUS = 22; 1074 SHOW_PROCESSLIST = 23; 1075 SHOW_TABLE_STATUS = 24; 1076 SHOW_TARGET = 25; 1077 SHOW_COLLATION = 26; 1078 LOCK_TABLES = 27; 1079 UNLOCK_TABLES = 28; 1080 CREATE_SEQUENCE = 29; 1081 ALTER_SEQUENCE = 30; 1082 DROP_SEQUENCE = 31; 1083 SHOW_SEQUENCES = 32; 1084 SHOW_CONNECTORS = 33; 1085 SHOW_UPGRADE = 34; 1086 } 1087 //DataDefinition type 1088 DdlType ddl_type = 1; 1089 1090 //other show statement we will rewrite to a select statement 1091 //then we will get a Query 1092 //eg: 'show databases' will rewrite to 'select md.datname as `Database` from mo_database md' 1093 Query query = 2; 1094 1095 oneof definition { 1096 CreateDatabase create_database = 3; 1097 AlterDatabase alter_database = 4; 1098 DropDatabase drop_database = 5; 1099 CreateTable create_table = 6; 1100 AlterTable alter_table = 7; 1101 DropTable drop_table = 8; 1102 CreateIndex create_index = 9; 1103 AlterIndex alter_index = 10; 1104 DropIndex drop_index = 11; 1105 TruncateTable truncate_table = 12; 1106 ShowVariables show_variables = 13; 1107 AlterView alter_view = 14; 1108 LockTables lock_tables = 15; 1109 UnLockTables unlock_tables = 16; 1110 CreateSequence create_sequence = 17; 1111 DropSequence drop_sequence = 18; 1112 AlterSequence alter_sequence = 19; 1113 1114 } 1115 } 1116 1117 1118 message SubscriptionOption{ 1119 string from = 1; 1120 string publication = 2; 1121 } 1122 1123 message CreateDatabase { 1124 bool if_not_exists = 1; 1125 string database = 2; 1126 SubscriptionOption subscription_option = 3; 1127 string sql = 4; 1128 } 1129 1130 message AlterDatabase { 1131 bool if_exists = 1; 1132 string database = 2; 1133 } 1134 1135 message DropDatabase { 1136 bool if_exists = 1; 1137 string database = 2; 1138 uint64 database_id = 3; 1139 // drop database should delete fk records related to this database 1140 // from mo_foreign_keys 1141 string updateFkSql = 4; 1142 // drop database should check mo_foreign_keys to find fk records 1143 // that refer to this database before dropping the database 1144 string checkFKSql = 5; 1145 } 1146 1147 message FkColName { 1148 repeated string cols = 1; 1149 } 1150 1151 /* ForeignKeyInfo holds the fk forward reference. 1152 1153 Example: t2(b) --fk--> t1(a) but t1 defined after t2 1154 1155 set foreign_key_checks=0; 1156 1157 create table t2(b int, constraint c1 foreign key (b) references t1(a)); 1158 1159 create table t1(a int primary key); 1160 1161 The reason we need ForeignKeyInfo instead of using ForeignKeyDef is that: 1162 1163 ForeignKeyDef only has table id, column id that does not exist in handling fk forward reference. 1164 ForeignKeyDef does not have database name, table name and column names, 1165 ForeignKeyInfo also has the ForeignKeyDef internally that holds the child table fk definition. 1166 */ 1167 message ForeignKeyInfo{ 1168 string db = 1; // database name of child table 1169 string table = 2; // child table name 1170 FkColName cols = 3; // fk names in child table 1171 FkColName colsReferred = 4; // referred names in parent table 1172 ForeignKeyDef def = 5; //child table fk def 1173 } 1174 1175 message CreateTable { 1176 bool if_not_exists = 1; 1177 bool temporary = 2; 1178 string database = 3; 1179 bool replace = 4; 1180 TableDef table_def = 5; 1181 repeated TableDef index_tables = 6; 1182 // we need the db/table name of foreign key when create table. but we don't need it in ForeignKeyDef 1183 repeated string fk_dbs = 7; 1184 repeated string fk_tables = 8; 1185 // we need column name when create table, but not in ForeignKeyDef 1186 repeated FkColName fk_cols = 9; 1187 repeated TableDef partition_tables = 10;// partition tables for partitions 1188 string create_as_select_sql = 11; 1189 // create table may insert fk records related to this table 1190 // into mo_foreign_keys 1191 repeated string updateFkSqls = 12; 1192 // fks forward reference to me 1193 repeated ForeignKeyInfo fksReferToMe = 13; 1194 } 1195 1196 message AlterTableDrop { 1197 enum Typ { 1198 COLUMN = 0; 1199 INDEX = 1; 1200 KEY = 2; 1201 PRIMARY_KEY = 3; 1202 FOREIGN_KEY = 4; 1203 } 1204 Typ typ = 1; 1205 string name = 2; 1206 string index_table_name = 3; 1207 } 1208 1209 message AlterTableAddFk { 1210 string db_name = 1; 1211 string table_name = 2; 1212 repeated string cols = 3; 1213 ForeignKeyDef fkey = 4; 1214 } 1215 1216 message AlterTableAddIndex { 1217 string db_name = 1; 1218 string table_name = 2; 1219 string origin_table_primary_key = 3; 1220 CreateTable indexInfo = 4; 1221 bool index_table_exist = 5; 1222 } 1223 1224 message AlterTableDropIndex { 1225 string db_name = 1; 1226 string table_name = 2; 1227 string index_name = 3; 1228 string index_table_name = 4; 1229 } 1230 1231 message AlterTableAlterIndex { 1232 string db_name = 1; 1233 string table_name = 2; 1234 string index_name = 3; 1235 bool visible = 4; 1236 } 1237 1238 message AlterTableAlterReIndex { 1239 string db_name = 1; 1240 string table_name = 2; 1241 string index_name = 3; 1242 int64 index_algo_param_list = 4; 1243 } 1244 1245 message AlterTableAddPartition { 1246 repeated PartitionItem definitions = 1; 1247 repeated TableDef partition_tables = 2; 1248 PartitionByDef PartitionDef = 3; 1249 } 1250 1251 message AlterTableComment { 1252 string new_comment = 1; 1253 } 1254 1255 message AlterTableName { 1256 string old_name = 1; 1257 string new_name = 2; 1258 } 1259 1260 message AlterAddColumn { 1261 string name = 1; 1262 string pre_name = 2; 1263 Type type = 3 [(gogoproto.nullable) = false]; 1264 int32 pos = 4; 1265 } 1266 1267 message AlterDropColumn { 1268 uint32 idx = 1; 1269 uint32 seq = 2; 1270 } 1271 1272 message AlterTable { 1273 enum AlgorithmType { 1274 DEFAULT = 0; 1275 COPY = 1; 1276 INSTANT = 2; 1277 INPLACE = 3; 1278 } 1279 message Action { 1280 oneof action { 1281 AlterTableDrop drop = 1; 1282 AlterTableAddFk add_fk = 2; 1283 AlterTableAddIndex add_index = 3; 1284 AlterTableAlterIndex alter_index = 4; 1285 AlterTableComment alter_comment = 5; 1286 AlterTableName alter_name = 6; 1287 AlterAddColumn add_column = 7; 1288 AlterDropColumn drop_column = 8; 1289 AlterTableAlterReIndex alter_reindex = 9; 1290 AlterTableAddPartition addPartition = 10; 1291 }; 1292 } 1293 string database = 1; 1294 TableDef table_def = 2; 1295 TableDef copy_table_def = 3; 1296 bool is_cluster_table = 4; 1297 repeated Action actions = 5; 1298 AlgorithmType algorithm_type = 6; 1299 string create_tmp_table_sql = 7; 1300 string insert_tmp_data_sql = 8; 1301 string create_table_sql = 9; 1302 string insert_data_sql = 10; 1303 map<uint64, ColDef> change_tbl_colId_map = 11; 1304 //detect fk self refer constraint 1305 repeated string detectSqls= 12; 1306 // alter table may insert fk records related to this table 1307 // into mo_foreign_keys 1308 repeated string updateFkSqls = 13; 1309 } 1310 1311 message DropTable { 1312 bool if_exists = 1; 1313 string database = 2; 1314 string table = 3; 1315 repeated string index_table_names = 4; 1316 ClusterTable cluster_table = 5; 1317 uint64 table_id = 6; 1318 repeated uint64 foreign_tbl = 7; 1319 repeated string partition_table_names = 8; 1320 bool isView = 9; 1321 TableDef table_def = 10; 1322 // drop table may delete fk records related to this table 1323 // into mo_foreign_keys 1324 repeated string updateFkSqls = 11; 1325 //fk child table id that refers to me 1326 repeated uint64 fkChildTblsReferToMe = 12; 1327 } 1328 1329 message AlterView { 1330 bool if_exists = 1; 1331 string database = 2; 1332 TableDef table_def = 4; 1333 } 1334 1335 message CreateSequence { 1336 bool if_not_exists =1; 1337 string database =2; 1338 TableDef table_def =3; 1339 } 1340 1341 message DropSequence { 1342 bool if_exists = 1; 1343 string database =2; 1344 string table =3; 1345 uint64 table_id = 4; 1346 } 1347 1348 message AlterSequence { 1349 bool if_exists =1; 1350 string database =2; 1351 TableDef table_def =3; 1352 } 1353 1354 message CreateIndex { 1355 string database = 1; 1356 string table = 2; 1357 TableDef table_def = 3; 1358 string origin_table_primary_key = 4; 1359 CreateTable index = 5; 1360 bool table_exist = 6; 1361 } 1362 1363 message AlterIndex { 1364 string index = 1; 1365 } 1366 1367 message DropIndex { 1368 string database = 1; 1369 string table = 2; 1370 string index_name = 3; 1371 string index_table_name = 4; 1372 } 1373 1374 message TruncateTable { 1375 string database = 1; 1376 string table = 2; 1377 repeated string index_table_names = 3; 1378 repeated string partition_table_names = 4; 1379 ClusterTable cluster_table = 5; 1380 uint64 table_id = 6; 1381 repeated uint64 foreign_tbl = 7; 1382 bool is_delete = 8; 1383 } 1384 1385 message ClusterTable{ 1386 bool is_cluster_table = 1;//insert into a cluster table 1387 repeated uint32 accountIDs = 2;//insert data into the cluster table for every account 1388 int32 column_index_of_accountId = 3;//the column index of the account id in the cluster table 1389 } 1390 1391 message ShowVariables { 1392 bool global = 1; 1393 repeated Expr where = 2; 1394 } 1395 1396 message SetVariables { 1397 repeated SetVariablesItem items = 1; 1398 } 1399 1400 message SetVariablesItem { 1401 bool system = 1; 1402 bool global = 2; 1403 string name = 3; 1404 Expr value = 4; 1405 Expr reserved = 5; 1406 } 1407 1408 message Prepare { 1409 string name = 1; 1410 repeated ObjectRef schemas = 2; 1411 Plan plan = 3; 1412 repeated int32 param_types = 4; 1413 } 1414 1415 message Execute { 1416 string name = 1; 1417 repeated Expr args = 2; 1418 } 1419 1420 message Deallocate { 1421 string name = 1; 1422 } 1423 1424 message OtherDCL { 1425 repeated int32 paramTypes = 1; 1426 } 1427 1428 enum TableLockType { 1429 TableLockNone = 0; 1430 TableLockRead = 1; 1431 TableLockReadLocal = 2; 1432 TableLockWrite = 3; 1433 TableLockLowPriorityWrite = 4; 1434 } 1435 1436 message TableLockInfo { 1437 TableLockType lockType = 1; 1438 TableDef tableDef = 2; 1439 } 1440 1441 message LockTables { 1442 repeated TableLockInfo tableLocks = 1; 1443 } 1444 1445 message UnLockTables{} 1446 1447 message MetadataScanInfo { 1448 enum MetadataScanInfoType { 1449 COL_NAME = 0; 1450 OBJECT_NAME = 1; 1451 IS_HIDDEN = 2; 1452 OBJ_LOC = 3; 1453 CREATE_TS = 4; 1454 DELETE_TS = 5; 1455 ROWS_CNT = 6; 1456 NULL_CNT = 7; 1457 COMPRESS_SIZE = 8; 1458 ORIGIN_SIZE = 9; 1459 MIN = 10; 1460 MAX = 11; 1461 SUM = 12; 1462 } 1463 string col_name = 1; 1464 string object_name = 2; 1465 bool is_hidden = 3; 1466 bytes obj_loc = 4; 1467 bytes create_ts = 5; 1468 bytes delete_ts = 6; 1469 int64 row_cnt = 7; 1470 int64 null_cnt = 8; 1471 int64 compress_size = 9; 1472 int64 origin_size = 10; 1473 bytes zone_map = 11; 1474 }