github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/plan/meta_scan.go (about) 1 // Copyright 2022 Matrix Origin 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 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package plan 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/catalog" 19 "github.com/matrixorigin/matrixone/pkg/common/moerr" 20 "github.com/matrixorigin/matrixone/pkg/container/batch" 21 "github.com/matrixorigin/matrixone/pkg/container/types" 22 "github.com/matrixorigin/matrixone/pkg/container/vector" 23 "github.com/matrixorigin/matrixone/pkg/logutil" 24 "github.com/matrixorigin/matrixone/pkg/pb/plan" 25 "github.com/matrixorigin/matrixone/pkg/sql/colexec" 26 "github.com/matrixorigin/matrixone/pkg/sql/parsers/tree" 27 ) 28 29 var ( 30 MetaColDefs = []*plan.ColDef{ 31 { 32 Name: catalog.MetaColNames[catalog.QUERY_ID_IDX], 33 Typ: plan.Type{ 34 Id: int32(catalog.MetaColTypes[catalog.QUERY_ID_IDX].Oid), 35 NotNullable: false, 36 }, 37 }, 38 { 39 Name: catalog.MetaColNames[catalog.STATEMENT_IDX], 40 Typ: plan.Type{ 41 Id: int32(catalog.MetaColTypes[catalog.STATEMENT_IDX].Oid), 42 NotNullable: false, 43 }, 44 }, 45 { 46 Name: catalog.MetaColNames[catalog.ACCOUNT_ID_IDX], 47 Typ: plan.Type{ 48 Id: int32(catalog.MetaColTypes[catalog.ACCOUNT_ID_IDX].Oid), 49 NotNullable: false, 50 }, 51 }, 52 { 53 Name: catalog.MetaColNames[catalog.ROLE_ID_IDX], 54 Typ: plan.Type{ 55 Id: int32(catalog.MetaColTypes[catalog.ROLE_ID_IDX].Oid), 56 NotNullable: false, 57 }, 58 }, 59 { 60 Name: catalog.MetaColNames[catalog.RESULT_PATH_IDX], 61 Typ: plan.Type{ 62 Id: int32(catalog.MetaColTypes[catalog.RESULT_PATH_IDX].Oid), 63 NotNullable: false, 64 Width: 4, 65 }, 66 }, 67 { 68 Name: catalog.MetaColNames[catalog.CREATE_TIME_IDX], 69 Typ: plan.Type{ 70 Id: int32(catalog.MetaColTypes[catalog.CREATE_TIME_IDX].Oid), 71 NotNullable: false, 72 }, 73 }, 74 { 75 Name: catalog.MetaColNames[catalog.RESULT_SIZE_IDX], 76 Typ: plan.Type{ 77 Id: int32(catalog.MetaColTypes[catalog.RESULT_SIZE_IDX].Oid), 78 NotNullable: false, 79 }, 80 }, 81 { 82 Name: catalog.MetaColNames[catalog.TABLES_IDX], 83 Typ: plan.Type{ 84 Id: int32(catalog.MetaColTypes[catalog.TABLES_IDX].Oid), 85 NotNullable: false, 86 }, 87 }, 88 { 89 Name: catalog.MetaColNames[catalog.USER_ID_IDX], 90 Typ: plan.Type{ 91 Id: int32(catalog.MetaColTypes[catalog.USER_ID_IDX].Oid), 92 NotNullable: false, 93 }, 94 }, 95 { 96 Name: catalog.MetaColNames[catalog.EXPIRED_TIME_IDX], 97 Typ: plan.Type{ 98 Id: int32(catalog.MetaColTypes[catalog.EXPIRED_TIME_IDX].Oid), 99 NotNullable: false, 100 }, 101 }, 102 { 103 Name: catalog.MetaColNames[catalog.COLUMN_MAP_IDX], 104 Typ: plan.Type{ 105 Id: int32(catalog.MetaColTypes[catalog.COLUMN_MAP_IDX].Oid), 106 NotNullable: false, 107 }, 108 }, 109 } 110 ) 111 112 func (builder *QueryBuilder) buildMetaScan(tbl *tree.TableFunction, ctx *BindContext, exprs []*plan.Expr, childId int32) (int32, error) { 113 var err error 114 val, err := builder.compCtx.ResolveVariable("save_query_result", true, true) 115 if err == nil { 116 if v, _ := val.(int8); v == 0 { 117 return 0, moerr.NewNoConfig(builder.GetContext(), "save query result") 118 } else { 119 logutil.Infof("buildMetaScan : save query result: %v", v) 120 } 121 } else { 122 return 0, err 123 } 124 exprs[0], err = appendCastBeforeExpr(builder.GetContext(), exprs[0], plan.Type{ 125 Id: int32(types.T_uuid), 126 NotNullable: true, 127 }) 128 if err != nil { 129 return 0, err 130 } 131 // calculate uuid 132 vec, err := colexec.EvalExpressionOnce(builder.compCtx.GetProcess(), exprs[0], []*batch.Batch{batch.EmptyForConstFoldBatch}) 133 if err != nil { 134 return 0, err 135 } 136 uuid := vector.MustFixedCol[types.Uuid](vec)[0] 137 vec.Free(builder.compCtx.GetProcess().GetMPool()) 138 139 node := &plan.Node{ 140 NodeType: plan.Node_FUNCTION_SCAN, 141 Stats: &plan.Stats{}, 142 TableDef: &plan.TableDef{ 143 Name: uuid.ToString(), 144 TableType: "func_table", 145 TblFunc: &plan.TableFunction{ 146 Name: "meta_scan", 147 }, 148 Cols: MetaColDefs, 149 }, 150 BindingTags: []int32{builder.genNewTag()}, 151 Children: []int32{childId}, 152 TblFuncExprList: exprs, 153 } 154 return builder.appendNode(node, ctx), nil 155 }