YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/ptree/pt_create_index.h
Line
Count
Source (jump to first uncovered line)
1
//--------------------------------------------------------------------------------------------------
2
// Copyright (c) YugaByte, Inc.
3
//
4
// Tree node definitions for CREATE INDEX statement.
5
//--------------------------------------------------------------------------------------------------
6
7
#ifndef YB_YQL_CQL_QL_PTREE_PT_CREATE_INDEX_H_
8
#define YB_YQL_CQL_QL_PTREE_PT_CREATE_INDEX_H_
9
10
#include "yb/yql/cql/ql/ptree/pt_create_table.h"
11
12
namespace yb {
13
namespace ql {
14
15
//--------------------------------------------------------------------------------------------------
16
// CREATE INDEX statement.
17
18
class PTCreateIndex : public PTCreateTable {
19
 public:
20
  //------------------------------------------------------------------------------------------------
21
  // Public types.
22
  typedef MCSharedPtr<PTCreateIndex> SharedPtr;
23
  typedef MCSharedPtr<const PTCreateIndex> SharedPtrConst;
24
25
  //------------------------------------------------------------------------------------------------
26
  // Constructor and destructor.
27
  PTCreateIndex(MemoryContext *memctx,
28
                YBLocationPtr loc,
29
                bool is_backfill_deferred,
30
                bool is_unique,
31
                const MCSharedPtr<MCString>& name,
32
                const PTQualifiedNamePtr& table_name,
33
                const PTListNodePtr& columns,
34
                bool create_if_not_exists,
35
                const PTTablePropertyListNodePtr& ordering_list,
36
                const PTListNodePtr& covering,
37
                const PTExprPtr& where_clause);
38
  virtual ~PTCreateIndex();
39
40
  // Node type.
41
6.27k
  virtual TreeNodeOpcode opcode() const override {
42
6.27k
    return TreeNodeOpcode::kPTCreateIndex;
43
6.27k
  }
44
45
  // Support for shared_ptr.
46
  template<typename... TypeArgs>
47
507
  inline static PTCreateIndex::SharedPtr MakeShared(MemoryContext *memctx, TypeArgs&&... args) {
48
507
    return MCMakeShared<PTCreateIndex>(memctx, std::forward<TypeArgs>(args)...);
49
507
  }
50
51
  // Accessor methods.
52
0
  const MCSharedPtr<MCString>& name() const {
53
0
    return name_;
54
0
  }
55
880
  bool is_unique() const {
56
880
    return is_unique_;
57
880
  }
58
0
  const PTListNodePtr& covering() const {
59
0
    return covering_;
60
0
  }
61
62
  client::YBTableName yb_table_name() const override;
63
64
  client::YBTableName indexed_table_name() const;
65
66
0
  const std::shared_ptr<client::YBTable>& indexed_table() const {
67
0
    return table_;
68
0
  }
69
70
  const std::string& indexed_table_id() const;
71
72
880
  bool is_local() const {
73
880
    return is_local_;
74
880
  }
75
76
880
  bool is_backfill_deferred() const {
77
880
    return is_backfill_deferred_;
78
880
  }
79
80
440
  const MCVector<ColumnDesc>& column_descs() const {
81
440
    return column_descs_;
82
440
  }
83
84
569
  const PTExprPtr& where_clause() const {
85
569
    return where_clause_;
86
569
  }
87
88
  CHECKED_STATUS AppendIndexColumn(SemContext *sem_context, PTColumnDefinition *column);
89
90
  virtual CHECKED_STATUS ToTableProperties(TableProperties *table_properties) const override;
91
92
  // Node semantics analysis.
93
  virtual CHECKED_STATUS Analyze(SemContext *sem_context) override;
94
  void PrintSemanticAnalysisResult(SemContext *sem_context);
95
96
129
  const std::shared_ptr<std::set<uint32>>& where_clause_column_refs() const {
97
129
    return where_clause_column_refs_;
98
129
  }
99
100
 private:
101
  // Is it a unique index?
102
  const bool is_unique_ = false;
103
  // Should backfill be deferred
104
  const bool is_backfill_deferred_ = false;
105
  // Index name.
106
  MCSharedPtr<MCString> name_;
107
  // Additional covering columns.
108
  const PTListNodePtr covering_;
109
110
  // The semantic analyzer will decorate the following information.
111
  bool is_local_ = false;
112
  std::shared_ptr<client::YBTable> table_;
113
  MCVector<ColumnDesc> column_descs_;
114
115
  // Auto-include columns are primary-key columns in the data-table being indexed that are not yet
116
  // declared as part of the INDEX.
117
  MCList<PTIndexColumnPtr> auto_includes_;
118
119
  // Where clause is specified for partial indexes.
120
  PTExprPtr where_clause_;
121
122
  // Columns that are being referenced by the index predicate. There are populated in
123
  // IdxPredicateState during semantic analysis. We use this as a variable to pass them on to
124
  // the execution phase (since object of IdxPredicateState lives only till semantic analysis).
125
  std::shared_ptr<std::set<uint32>> where_clause_column_refs_;
126
};
127
128
class IdxPredicateState {
129
 public:
130
  explicit IdxPredicateState(MemoryContext *memctx, TreeNodeOpcode statement_type)
131
132
    : column_refs_(std::make_shared<std::set<uint32>>()) {
132
132
  }
133
134
  CHECKED_STATUS AnalyzeColumnOp(SemContext *sem_context,
135
                                 const PTRelationExpr *expr,
136
                                 const ColumnDesc *col_desc,
137
                                 PTExprPtr value,
138
                                 PTExprListNodePtr args = nullptr);
139
140
309
  std::shared_ptr<std::set<uint32>>& column_refs() {
141
309
    return column_refs_;
142
309
  }
143
144
 private:
145
  // Columns that are being referenced by the index predicate. These will later be stored in
146
  // IndexInfoPB so that other queries can use the column ids later when interacting with the
147
  // index.
148
  // TODO(Piyush): Use MCSet. Tried it, there were some issues when iterating over an MCSet.
149
  std::shared_ptr<std::set<uint32>> column_refs_;
150
};
151
152
}  // namespace ql
153
}  // namespace yb
154
155
#endif  // YB_YQL_CQL_QL_PTREE_PT_CREATE_INDEX_H_