summaryrefslogtreecommitdiff
path: root/storage/ndb/src/old_files/client/odbc/codegen/Code_expr_row.hpp
blob: 94527931dbae06814464e6dd1943f8d750bb6644 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/* Copyright (C) 2003 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#ifndef ODBC_CODEGEN_Code_expr_row_hpp
#define ODBC_CODEGEN_Code_expr_row_hpp

#include <vector>
#include <common/common.hpp>
#include <common/DataRow.hpp>
#include "Code_base.hpp"
#include "Code_expr.hpp"

class Plan_expr;

/**
 * @class Plan_expr_row
 * @brief Row of expressions in PlanTree
 *
 * Used for select, value, and order by rows.
 */
class Plan_expr_row : public Plan_base {
public:
    Plan_expr_row(Plan_root* root);
    virtual ~Plan_expr_row();
    Plan_base* analyze(Ctx& ctx, Ctl& ctl);
    Exec_base* codegen(Ctx& ctx, Ctl& ctl);
    void print(Ctx& ctx);
    // children
    void setAsterisk();
    bool getAsterisk() const;
    unsigned getSize() const;
    Plan_expr* getExpr(unsigned i) const;
    void setExpr(unsigned i, Plan_expr* expr);
    void addExpr(Plan_expr* expr);
    void addExpr(Plan_expr* expr, const BaseString& alias);
    void setAlias(unsigned i, const BaseString& alias);
    void addExpr(Plan_expr* expr, bool asc);
    bool anyAggr() const;
    bool allBound() const;
    bool isAllGroupBy(const Plan_expr_row* row) const;
protected:
    friend class Plan_query;
    friend class Plan_query_sort;
    bool m_asterisk;		// early plan node type
    ExprVector m_exprList;
    typedef std::vector<BaseString> AliasList;
    AliasList m_aliasList;
    typedef std::vector<bool> AscList;
    AscList m_ascList;
    bool m_anyAggr;		// at least one aggreate
    bool m_allBound;		// all bound
};

inline
Plan_expr_row::Plan_expr_row(Plan_root* root) :
    Plan_base(root),
    m_asterisk(false),
    m_exprList(1),
    m_aliasList(1),
    m_ascList(1),
    m_anyAggr(false),
    m_allBound(false)
{
}

// children

inline void
Plan_expr_row::setAsterisk()
{
    m_asterisk = true;
}

inline bool
Plan_expr_row::getAsterisk() const
{
    return m_asterisk;
}

inline unsigned
Plan_expr_row::getSize() const
{
    ctx_assert(m_exprList.size() >= 1);
    return m_exprList.size() - 1;
}

inline void
Plan_expr_row::addExpr(Plan_expr* expr)
{
    ctx_assert(expr != 0);
    addExpr(expr, expr->m_alias);
}

inline void
Plan_expr_row::addExpr(Plan_expr* expr, const BaseString& alias)
{
    ctx_assert(expr != 0);
    m_exprList.push_back(expr);
    m_aliasList.push_back(alias);
}

inline void
Plan_expr_row::addExpr(Plan_expr* expr, bool asc)
{
    ctx_assert(expr != 0);
    m_exprList.push_back(expr);
    m_ascList.push_back(asc);
}

inline void
Plan_expr_row::setExpr(unsigned i, Plan_expr* expr)
{
    ctx_assert(1 <= i && i < m_exprList.size() && expr != 0);
    m_exprList[i] = expr;
}

inline Plan_expr*
Plan_expr_row::getExpr(unsigned i) const
{
    ctx_assert(1 <= i && i < m_exprList.size() && m_exprList[i] != 0);
    return m_exprList[i];
}

inline void
Plan_expr_row::setAlias(unsigned i, const BaseString& alias)
{
    ctx_assert(1 <= i && i < m_aliasList.size());
    m_aliasList[i] = alias;
}

inline bool
Plan_expr_row::anyAggr() const
{
    return m_anyAggr;
}

inline bool
Plan_expr_row::allBound() const
{
    return m_allBound;
}

/**
 * @class Expr_expr_row
 * @brief Row of expressions in ExecTree
 */
class Exec_expr_row : public Exec_base {
public:
    class Code : public Exec_base::Code {
    public:
	typedef char Alias[40];
	Code(const SqlSpecs& sqlSpecs, const Alias* aliasList);
	virtual ~Code();
	const SqlSpecs& sqlSpecs() const;
	const char* getAlias(unsigned i) const;
    protected:
	friend class Exec_expr_row;
	const SqlSpecs m_sqlSpecs;
	const Alias* m_aliasList;
    };
    class Data : public Exec_base::Data {
    public:
	Data(const SqlRow& sqlRow);
	virtual ~Data();
	const SqlRow& sqlRow() const;
    protected:
	friend class Exec_expr_row;
	SqlRow m_sqlRow;
    };
    Exec_expr_row(Exec_root* root, unsigned size);
    virtual ~Exec_expr_row();
    void alloc(Ctx& ctx, Ctl& ctl);
    void evaluate(Ctx& ctx, Ctl& ctl);
    void close(Ctx& ctx);
    void print(Ctx& ctx);
    // children
    const Code& getCode() const;
    Data& getData() const;
    Exec_expr* getExpr(unsigned i) const;
    void setExpr(unsigned i, Exec_expr* expr);
protected:
    Exec_expr** m_expr;		// numbered from 1
    unsigned m_size;
};

inline
Exec_expr_row::Code::Code(const SqlSpecs& sqlSpecs, const Alias* aliasList) :
    m_sqlSpecs(sqlSpecs),
    m_aliasList(aliasList)
{
}

inline const SqlSpecs&
Exec_expr_row::Code::sqlSpecs() const
{
    return m_sqlSpecs;
}

inline const char*
Exec_expr_row::Code::getAlias(unsigned i) const
{
    ctx_assert(1 <= i && i <= m_sqlSpecs.count() && m_aliasList != 0);
    return m_aliasList[i];
}

inline
Exec_expr_row::Data::Data(const SqlRow& sqlRow) :
    m_sqlRow(sqlRow)
{
}

inline const SqlRow&
Exec_expr_row::Data::sqlRow() const
{
    return m_sqlRow;
}

inline
Exec_expr_row::Exec_expr_row(Exec_root* root, unsigned size) :
    Exec_base(root),
    m_expr(new Exec_expr* [1 + size]),
    m_size(size)
{
    m_expr[0] = (Exec_expr*)-1;
    for (unsigned i = 1; i <= m_size; i++)
	m_expr[i] = 0;
}

// children

inline const Exec_expr_row::Code&
Exec_expr_row::getCode() const
{
    const Code* code = static_cast<const Code*>(m_code);
    return *code;
}

inline Exec_expr_row::Data&
Exec_expr_row::getData() const
{
    Data* data = static_cast<Data*>(m_data);
    return *data;
}

inline Exec_expr*
Exec_expr_row::getExpr(unsigned i) const
{
    ctx_assert(1 <= i && i <= m_size && m_expr != 0 && m_expr[i] != 0);
    return m_expr[i];
}

inline void
Exec_expr_row::setExpr(unsigned i, Exec_expr* expr)
{
    ctx_assert(1 <= i && i <= m_size && m_expr != 0 && m_expr[i] == 0);
    m_expr[i] = expr;
}

#endif