YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/yql/pggate/pggate.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#ifndef YB_YQL_PGGATE_PGGATE_H_
15
#define YB_YQL_PGGATE_PGGATE_H_
16
17
#include <algorithm>
18
#include <functional>
19
#include <thread>
20
#include <unordered_map>
21
22
#include <boost/preprocessor/cat.hpp>
23
#include <boost/preprocessor/seq/for_each.hpp>
24
25
#include "yb/util/metrics.h"
26
#include "yb/util/mem_tracker.h"
27
#include "yb/common/ybc_util.h"
28
29
#include "yb/client/callbacks.h"
30
#include "yb/client/async_initializer.h"
31
#include "yb/server/server_base_options.h"
32
33
#include "yb/rpc/rpc_fwd.h"
34
35
#include "yb/yql/pggate/pg_client.h"
36
#include "yb/yql/pggate/pg_env.h"
37
#include "yb/yql/pggate/pg_session.h"
38
#include "yb/yql/pggate/pg_statement.h"
39
#include "yb/yql/pggate/type_mapping.h"
40
41
#include "yb/server/hybrid_clock.h"
42
#include "yb/yql/pggate/ybc_pggate.h"
43
44
namespace yb {
45
namespace pggate {
46
47
//--------------------------------------------------------------------------------------------------
48
49
class PggateOptions : public yb::server::ServerBaseOptions {
50
 public:
51
  static const uint16_t kDefaultPort = 5432;
52
  static const uint16_t kDefaultWebPort = 13000;
53
54
  PggateOptions();
55
6.06k
  virtual ~PggateOptions() {}
56
};
57
58
struct PgApiContext {
59
  struct MessengerHolder {
60
    std::unique_ptr<rpc::SecureContext> security_context;
61
    std::unique_ptr<rpc::Messenger> messenger;
62
63
    MessengerHolder(
64
        std::unique_ptr<rpc::SecureContext> security_context,
65
        std::unique_ptr<rpc::Messenger> messenger);
66
    MessengerHolder(MessengerHolder&&);
67
68
    ~MessengerHolder();
69
  };
70
71
  std::unique_ptr<MetricRegistry> metric_registry;
72
  scoped_refptr<MetricEntity> metric_entity;
73
  std::shared_ptr<MemTracker> mem_tracker;
74
  MessengerHolder messenger_holder;
75
  std::unique_ptr<rpc::ProxyCache> proxy_cache;
76
77
  PgApiContext();
78
  PgApiContext(PgApiContext&&);
79
  ~PgApiContext();
80
};
81
82
//--------------------------------------------------------------------------------------------------
83
// Implements support for CAPI.
84
class PgApiImpl {
85
 public:
86
  PgApiImpl(PgApiContext context, const YBCPgTypeEntity *YBCDataTypeTable, int count,
87
            YBCPgCallbacks pg_callbacks);
88
  virtual ~PgApiImpl();
89
90
2.25k
  const YBCPgCallbacks* pg_callbacks() {
91
2.25k
    return &pg_callbacks_;
92
2.25k
  }
93
94
  void ResetCatalogReadTime();
95
96
  // Initialize ENV within which PGSQL calls will be executed.
97
  CHECKED_STATUS CreateEnv(PgEnv **pg_env);
98
  CHECKED_STATUS DestroyEnv(PgEnv *pg_env);
99
100
  // Initialize a session to process statements that come from the same client connection.
101
  // If database_name is empty, a session is created without connecting to any database.
102
  CHECKED_STATUS InitSession(const PgEnv *pg_env, const string& database_name);
103
104
  // YB Memctx: Create, Destroy, and Reset must be "static" because a few contexts are created
105
  //            before YugaByte environments including PgGate are created and initialized.
106
  // Create YB Memctx. Each memctx will be associated with a Postgres's MemoryContext.
107
  static PgMemctx *CreateMemctx();
108
  // Destroy YB Memctx.
109
  static CHECKED_STATUS DestroyMemctx(PgMemctx *memctx);
110
  // Reset YB Memctx.
111
  static CHECKED_STATUS ResetMemctx(PgMemctx *memctx);
112
  // Cache statements in YB Memctx. When Memctx is destroyed, the statement is destructed.
113
  CHECKED_STATUS AddToCurrentPgMemctx(std::unique_ptr<PgStatement> stmt,
114
                                      PgStatement **handle);
115
  // Cache table descriptor in YB Memctx. When Memctx is destroyed, the descriptor is destructed.
116
  CHECKED_STATUS AddToCurrentPgMemctx(size_t table_desc_id,
117
                                      const PgTableDescPtr &table_desc);
118
  // Read table descriptor that was cached in YB Memctx.
119
  CHECKED_STATUS GetTabledescFromCurrentPgMemctx(size_t table_desc_id, PgTableDesc **handle);
120
121
  // Invalidate the sessions table cache.
122
  CHECKED_STATUS InvalidateCache();
123
124
  // Get the gflag TEST_ysql_disable_transparent_cache_refresh_retry.
125
  bool GetDisableTransparentCacheRefreshRetry();
126
127
  Result<bool> IsInitDbDone();
128
129
  Result<uint64_t> GetSharedCatalogVersion();
130
  Result<uint64_t> GetSharedAuthKey();
131
132
  // Setup the table to store sequences data.
133
  CHECKED_STATUS CreateSequencesDataTable();
134
135
  CHECKED_STATUS InsertSequenceTuple(int64_t db_oid,
136
                                     int64_t seq_oid,
137
                                     uint64_t ysql_catalog_version,
138
                                     int64_t last_val,
139
                                     bool is_called);
140
141
  CHECKED_STATUS UpdateSequenceTupleConditionally(int64_t db_oid,
142
                                                  int64_t seq_oid,
143
                                                  uint64_t ysql_catalog_version,
144
                                                  int64_t last_val,
145
                                                  bool is_called,
146
                                                  int64_t expected_last_val,
147
                                                  bool expected_is_called,
148
                                                  bool *skipped);
149
150
  CHECKED_STATUS UpdateSequenceTuple(int64_t db_oid,
151
                                     int64_t seq_oid,
152
                                     uint64_t ysql_catalog_version,
153
                                     int64_t last_val,
154
                                     bool is_called,
155
                                     bool* skipped);
156
157
  CHECKED_STATUS ReadSequenceTuple(int64_t db_oid,
158
                                   int64_t seq_oid,
159
                                   uint64_t ysql_catalog_version,
160
                                   int64_t *last_val,
161
                                   bool *is_called);
162
163
  CHECKED_STATUS DeleteSequenceTuple(int64_t db_oid, int64_t seq_oid);
164
165
  void DeleteStatement(PgStatement *handle);
166
167
  // Search for type_entity.
168
  const YBCPgTypeEntity *FindTypeEntity(int type_oid);
169
170
  //------------------------------------------------------------------------------------------------
171
  // Connect database. Switch the connected database to the given "database_name".
172
  CHECKED_STATUS ConnectDatabase(const char *database_name);
173
174
  // Determine whether the given database is colocated.
175
  CHECKED_STATUS IsDatabaseColocated(const PgOid database_oid, bool *colocated);
176
177
  // Create database.
178
  CHECKED_STATUS NewCreateDatabase(const char *database_name,
179
                                   PgOid database_oid,
180
                                   PgOid source_database_oid,
181
                                   PgOid next_oid,
182
                                   const bool colocated,
183
                                   PgStatement **handle);
184
  CHECKED_STATUS ExecCreateDatabase(PgStatement *handle);
185
186
  // Drop database.
187
  CHECKED_STATUS NewDropDatabase(const char *database_name,
188
                                 PgOid database_oid,
189
                                 PgStatement **handle);
190
  CHECKED_STATUS ExecDropDatabase(PgStatement *handle);
191
192
  // Alter database.
193
  CHECKED_STATUS NewAlterDatabase(const char *database_name,
194
                                 PgOid database_oid,
195
                                 PgStatement **handle);
196
  CHECKED_STATUS AlterDatabaseRenameDatabase(PgStatement *handle, const char *newname);
197
  CHECKED_STATUS ExecAlterDatabase(PgStatement *handle);
198
199
  // Reserve oids.
200
  CHECKED_STATUS ReserveOids(PgOid database_oid,
201
                             PgOid next_oid,
202
                             uint32_t count,
203
                             PgOid *begin_oid,
204
                             PgOid *end_oid);
205
206
  CHECKED_STATUS GetCatalogMasterVersion(uint64_t *version);
207
208
  // Load table.
209
  Result<PgTableDescPtr> LoadTable(const PgObjectId& table_id);
210
211
  // Invalidate the cache entry corresponding to table_id from the PgSession table cache.
212
  void InvalidateTableCache(const PgObjectId& table_id);
213
214
  //------------------------------------------------------------------------------------------------
215
  // Create and drop tablegroup.
216
217
  CHECKED_STATUS NewCreateTablegroup(const char *database_name,
218
                                     const PgOid database_oid,
219
                                     const PgOid tablegroup_oid,
220
                                     const PgOid tablespace_oid,
221
                                     PgStatement **handle);
222
223
  CHECKED_STATUS ExecCreateTablegroup(PgStatement *handle);
224
225
  CHECKED_STATUS NewDropTablegroup(const PgOid database_oid,
226
                                   const PgOid tablegroup_oid,
227
                                   PgStatement **handle);
228
229
  CHECKED_STATUS ExecDropTablegroup(PgStatement *handle);
230
231
  //------------------------------------------------------------------------------------------------
232
  // Create, alter and drop table.
233
  CHECKED_STATUS NewCreateTable(const char *database_name,
234
                                const char *schema_name,
235
                                const char *table_name,
236
                                const PgObjectId& table_id,
237
                                bool is_shared_table,
238
                                bool if_not_exist,
239
                                bool add_primary_key,
240
                                const bool colocated,
241
                                const PgObjectId& tablegroup_oid,
242
                                const ColocationId colocation_id,
243
                                const PgObjectId& tablespace_oid,
244
                                const PgObjectId& matview_pg_table_oid,
245
                                PgStatement **handle);
246
247
  CHECKED_STATUS CreateTableAddColumn(PgStatement *handle, const char *attr_name, int attr_num,
248
                                      const YBCPgTypeEntity *attr_type, bool is_hash,
249
                                      bool is_range, bool is_desc, bool is_nulls_first);
250
251
  CHECKED_STATUS CreateTableSetNumTablets(PgStatement *handle, int32_t num_tablets);
252
253
  CHECKED_STATUS AddSplitBoundary(PgStatement *handle, PgExpr **exprs, int expr_count);
254
255
  CHECKED_STATUS ExecCreateTable(PgStatement *handle);
256
257
  CHECKED_STATUS NewAlterTable(const PgObjectId& table_id,
258
                               PgStatement **handle);
259
260
  CHECKED_STATUS AlterTableAddColumn(PgStatement *handle, const char *name,
261
                                     int order, const YBCPgTypeEntity *attr_type);
262
263
  CHECKED_STATUS AlterTableRenameColumn(PgStatement *handle, const char *oldname,
264
                                        const char *newname);
265
266
  CHECKED_STATUS AlterTableDropColumn(PgStatement *handle, const char *name);
267
268
  CHECKED_STATUS AlterTableRenameTable(PgStatement *handle, const char *db_name,
269
                                       const char *newname);
270
271
  CHECKED_STATUS ExecAlterTable(PgStatement *handle);
272
273
  CHECKED_STATUS NewDropTable(const PgObjectId& table_id,
274
                              bool if_exist,
275
                              PgStatement **handle);
276
277
  CHECKED_STATUS NewTruncateTable(const PgObjectId& table_id,
278
                                  PgStatement **handle);
279
280
  CHECKED_STATUS ExecTruncateTable(PgStatement *handle);
281
282
  CHECKED_STATUS GetTableDesc(const PgObjectId& table_id,
283
                              PgTableDesc **handle);
284
285
  Result<YBCPgColumnInfo> GetColumnInfo(YBCPgTableDesc table_desc,
286
                                        int16_t attr_number);
287
288
  CHECKED_STATUS DmlModifiesRow(PgStatement *handle, bool *modifies_row);
289
290
  CHECKED_STATUS SetIsSysCatalogVersionChange(PgStatement *handle);
291
292
  CHECKED_STATUS SetCatalogCacheVersion(PgStatement *handle, uint64_t catalog_cache_version);
293
294
  //------------------------------------------------------------------------------------------------
295
  // Create and drop index.
296
  CHECKED_STATUS NewCreateIndex(const char *database_name,
297
                                const char *schema_name,
298
                                const char *index_name,
299
                                const PgObjectId& index_id,
300
                                const PgObjectId& table_id,
301
                                bool is_shared_index,
302
                                bool is_unique_index,
303
                                const bool skip_index_backfill,
304
                                bool if_not_exist,
305
                                const PgObjectId& tablegroup_oid,
306
                                const YBCPgOid& colocation_id,
307
                                const PgObjectId& tablespace_oid,
308
                                PgStatement **handle);
309
310
  CHECKED_STATUS CreateIndexAddColumn(PgStatement *handle, const char *attr_name, int attr_num,
311
                                      const YBCPgTypeEntity *attr_type, bool is_hash,
312
                                      bool is_range, bool is_desc, bool is_nulls_first);
313
314
  CHECKED_STATUS CreateIndexSetNumTablets(PgStatement *handle, int32_t num_tablets);
315
316
  CHECKED_STATUS CreateIndexAddSplitRow(PgStatement *handle, int num_cols,
317
                                        YBCPgTypeEntity **types, uint64_t *data);
318
319
  CHECKED_STATUS ExecCreateIndex(PgStatement *handle);
320
321
  CHECKED_STATUS NewDropIndex(const PgObjectId& index_id,
322
                              bool if_exist,
323
                              PgStatement **handle);
324
325
  CHECKED_STATUS ExecPostponedDdlStmt(PgStatement *handle);
326
327
  CHECKED_STATUS BackfillIndex(const PgObjectId& table_id);
328
329
  //------------------------------------------------------------------------------------------------
330
  // All DML statements
331
  CHECKED_STATUS DmlAppendTarget(PgStatement *handle, PgExpr *expr);
332
333
  CHECKED_STATUS DmlAppendQual(PgStatement *handle, PgExpr *expr);
334
335
  CHECKED_STATUS DmlAppendColumnRef(PgStatement *handle, PgExpr *colref);
336
337
  // Binding Columns: Bind column with a value (expression) in a statement.
338
  // + This API is used to identify the rows you want to operate on. If binding columns are not
339
  //   there, that means you want to operate on all rows (full scan). You can view this as a
340
  //   a definitions of an initial rowset or an optimization over full-scan.
341
  //
342
  // + There are some restrictions on when BindColumn() can be used.
343
  //   Case 1: INSERT INTO tab(x) VALUES(x_expr)
344
  //   - BindColumn() can be used for BOTH primary-key and regular columns.
345
  //   - This bind-column function is used to bind "x" with "x_expr", and "x_expr" that can contain
346
  //     bind-variables (placeholders) and constants whose values can be updated for each execution
347
  //     of the same allocated statement.
348
  //
349
  //   Case 2: SELECT / UPDATE / DELETE <WHERE key = "key_expr">
350
  //   - BindColumn() can only be used for primary-key columns.
351
  //   - This bind-column function is used to bind the primary column "key" with "key_expr" that can
352
  //     contain bind-variables (placeholders) and constants whose values can be updated for each
353
  //     execution of the same allocated statement.
354
  CHECKED_STATUS DmlBindColumn(YBCPgStatement handle, int attr_num, YBCPgExpr attr_value);
355
  CHECKED_STATUS DmlBindColumnCondBetween(YBCPgStatement handle, int attr_num, YBCPgExpr attr_value,
356
      YBCPgExpr attr_value_end);
357
  CHECKED_STATUS DmlBindColumnCondIn(YBCPgStatement handle, int attr_num, int n_attr_values,
358
      YBCPgExpr *attr_value);
359
360
  CHECKED_STATUS DmlBindHashCode(PgStatement *handle, bool start_valid,
361
                                bool start_inclusive, uint64_t start_hash_val,
362
                                bool end_valid, bool end_inclusive,
363
                                uint64_t end_hash_val);
364
365
  CHECKED_STATUS DmlAddRowUpperBound(YBCPgStatement handle,
366
                                    int n_col_values,
367
                                    YBCPgExpr *col_values,
368
                                    bool is_inclusive);
369
370
  CHECKED_STATUS DmlAddRowLowerBound(YBCPgStatement handle,
371
                                    int n_col_values,
372
                                    YBCPgExpr *col_values,
373
                                    bool is_inclusive);
374
375
  // Binding Tables: Bind the whole table in a statement.  Do not use with BindColumn.
376
  CHECKED_STATUS DmlBindTable(YBCPgStatement handle);
377
378
  // Utility method to get the info for column 'attr_num'.
379
  Result<YBCPgColumnInfo> DmlGetColumnInfo(YBCPgStatement handle, int attr_num);
380
381
  // API for SET clause.
382
  CHECKED_STATUS DmlAssignColumn(YBCPgStatement handle, int attr_num, YBCPgExpr attr_value);
383
384
  // This function is to fetch the targets in YBCPgDmlAppendTarget() from the rows that were defined
385
  // by YBCPgDmlBindColumn().
386
  CHECKED_STATUS DmlFetch(PgStatement *handle, int32_t natts, uint64_t *values, bool *isnulls,
387
                          PgSysColumns *syscols, bool *has_data);
388
389
  // Utility method that checks stmt type and calls exec insert, update, or delete internally.
390
  CHECKED_STATUS DmlExecWriteOp(PgStatement *handle, int32_t *rows_affected_count);
391
392
  // This function adds a primary column to be used in the construction of the tuple id (ybctid).
393
  CHECKED_STATUS DmlAddYBTupleIdColumn(PgStatement *handle, int attr_num, uint64_t datum,
394
                                       bool is_null, const YBCPgTypeEntity *type_entity);
395
396
  using YBTupleIdProcessor = std::function<Status(const Slice&)>;
397
  CHECKED_STATUS ProcessYBTupleId(const YBCPgYBTupleIdDescriptor& descr,
398
                                  const YBTupleIdProcessor& processor);
399
400
  // DB Operations: SET, WHERE, ORDER_BY, GROUP_BY, etc.
401
  // + The following operations are run by DocDB.
402
  //   - API for "set_clause" (not yet implemented).
403
  //
404
  // + The following operations are run by Postgres layer. An API might be added to move these
405
  //   operations to DocDB.
406
  //   - API for "where_expr"
407
  //   - API for "order_by_expr"
408
  //   - API for "group_by_expr"
409
410
  // Buffer write operations.
411
  CHECKED_STATUS StartOperationsBuffering();
412
  CHECKED_STATUS StopOperationsBuffering();
413
  void ResetOperationsBuffering();
414
  CHECKED_STATUS FlushBufferedOperations();
415
416
  //------------------------------------------------------------------------------------------------
417
  // Insert.
418
  CHECKED_STATUS NewInsert(const PgObjectId& table_id,
419
                           bool is_single_row_txn,
420
                           PgStatement **handle);
421
422
  CHECKED_STATUS ExecInsert(PgStatement *handle);
423
424
  CHECKED_STATUS InsertStmtSetUpsertMode(PgStatement *handle);
425
426
  CHECKED_STATUS InsertStmtSetWriteTime(PgStatement *handle, const HybridTime write_time);
427
428
  CHECKED_STATUS InsertStmtSetIsBackfill(PgStatement *handle, const bool is_backfill);
429
430
  //------------------------------------------------------------------------------------------------
431
  // Update.
432
  CHECKED_STATUS NewUpdate(const PgObjectId& table_id,
433
                           bool is_single_row_txn,
434
                           PgStatement **handle);
435
436
  CHECKED_STATUS ExecUpdate(PgStatement *handle);
437
438
  //------------------------------------------------------------------------------------------------
439
  // Delete.
440
  CHECKED_STATUS NewDelete(const PgObjectId& table_id,
441
                           bool is_single_row_txn,
442
                           PgStatement **handle);
443
444
  CHECKED_STATUS ExecDelete(PgStatement *handle);
445
446
  CHECKED_STATUS DeleteStmtSetIsPersistNeeded(PgStatement *handle, const bool is_persist_needed);
447
448
  //------------------------------------------------------------------------------------------------
449
  // Colocated Truncate.
450
  CHECKED_STATUS NewTruncateColocated(const PgObjectId& table_id,
451
                                      bool is_single_row_txn,
452
                                      PgStatement **handle);
453
454
  CHECKED_STATUS ExecTruncateColocated(PgStatement *handle);
455
456
  //------------------------------------------------------------------------------------------------
457
  // Select.
458
  CHECKED_STATUS NewSelect(const PgObjectId& table_id,
459
                           const PgObjectId& index_id,
460
                           const PgPrepareParameters *prepare_params,
461
                           PgStatement **handle);
462
463
  CHECKED_STATUS SetForwardScan(PgStatement *handle, bool is_forward_scan);
464
465
  CHECKED_STATUS ExecSelect(PgStatement *handle, const PgExecParameters *exec_params);
466
467
  //------------------------------------------------------------------------------------------------
468
  // Analyze.
469
  CHECKED_STATUS NewSample(const PgObjectId& table_id,
470
                           const int targrows,
471
                           PgStatement **handle);
472
473
  CHECKED_STATUS InitRandomState(PgStatement *handle, double rstate_w, uint64 rand_state);
474
475
  CHECKED_STATUS SampleNextBlock(PgStatement *handle, bool *has_more);
476
477
  CHECKED_STATUS ExecSample(PgStatement *handle);
478
479
  CHECKED_STATUS GetEstimatedRowCount(PgStatement *handle, double *liverows, double *deadrows);
480
481
  //------------------------------------------------------------------------------------------------
482
  // Transaction control.
483
0
  PgTxnManager* GetPgTxnManager() { return pg_txn_manager_.get(); }
484
485
  CHECKED_STATUS BeginTransaction();
486
  CHECKED_STATUS RecreateTransaction();
487
  CHECKED_STATUS RestartTransaction();
488
  CHECKED_STATUS ResetTransactionReadPoint();
489
  CHECKED_STATUS RestartReadPoint();
490
  CHECKED_STATUS CommitTransaction();
491
  CHECKED_STATUS AbortTransaction();
492
  CHECKED_STATUS SetTransactionIsolationLevel(int isolation);
493
  CHECKED_STATUS SetTransactionReadOnly(bool read_only);
494
  CHECKED_STATUS SetTransactionDeferrable(bool deferrable);
495
  CHECKED_STATUS EnableFollowerReads(bool enable_follower_reads, int32_t staleness_ms);
496
  CHECKED_STATUS EnterSeparateDdlTxnMode();
497
  CHECKED_STATUS ExitSeparateDdlTxnMode();
498
  void ClearSeparateDdlTxnMode();
499
  CHECKED_STATUS SetActiveSubTransaction(SubTransactionId id);
500
  CHECKED_STATUS RollbackSubTransaction(SubTransactionId id);
501
502
  //------------------------------------------------------------------------------------------------
503
  // Expressions.
504
  // Column reference.
505
  CHECKED_STATUS NewColumnRef(
506
      PgStatement *handle, int attr_num, const PgTypeEntity *type_entity,
507
      bool collate_is_valid_non_c, const PgTypeAttrs *type_attrs, PgExpr **expr_handle);
508
509
  // Constant expressions.
510
  CHECKED_STATUS NewConstant(
511
      YBCPgStatement stmt, const YBCPgTypeEntity *type_entity, bool collate_is_valid_non_c,
512
      const char *collation_sortkey, uint64_t datum, bool is_null, YBCPgExpr *expr_handle);
513
  CHECKED_STATUS NewConstantVirtual(
514
      YBCPgStatement stmt, const YBCPgTypeEntity *type_entity,
515
      YBCPgDatumKind datum_kind, YBCPgExpr *expr_handle);
516
  CHECKED_STATUS NewConstantOp(
517
      YBCPgStatement stmt, const YBCPgTypeEntity *type_entity, bool collate_is_valid_non_c,
518
      const char *collation_sortkey, uint64_t datum, bool is_null, YBCPgExpr *expr_handle,
519
      bool is_gt);
520
521
  // TODO(neil) UpdateConstant should be merged into one.
522
  // Update constant.
523
  template<typename value_type>
524
1.22k
  CHECKED_STATUS UpdateConstant(PgExpr *expr, value_type value, bool is_null) {
525
1.22k
    if (expr->opcode() != PgExpr::Opcode::PG_EXPR_CONSTANT) {
526
      // Invalid handle.
527
0
      return STATUS(InvalidArgument, "Invalid expression handle for constant");
528
0
    }
529
1.22k
    down_cast<PgConstant*>(expr)->UpdateConstant(value, is_null);
530
1.22k
    return Status::OK();
531
1.22k
  }
yb::Status yb::pggate::PgApiImpl::UpdateConstant<short>(yb::pggate::PgExpr*, short, bool)
Line
Count
Source
524
43
  CHECKED_STATUS UpdateConstant(PgExpr *expr, value_type value, bool is_null) {
525
43
    if (expr->opcode() != PgExpr::Opcode::PG_EXPR_CONSTANT) {
526
      // Invalid handle.
527
0
      return STATUS(InvalidArgument, "Invalid expression handle for constant");
528
0
    }
529
43
    down_cast<PgConstant*>(expr)->UpdateConstant(value, is_null);
530
43
    return Status::OK();
531
43
  }
yb::Status yb::pggate::PgApiImpl::UpdateConstant<int>(yb::pggate::PgExpr*, int, bool)
Line
Count
Source
524
111
  CHECKED_STATUS UpdateConstant(PgExpr *expr, value_type value, bool is_null) {
525
111
    if (expr->opcode() != PgExpr::Opcode::PG_EXPR_CONSTANT) {
526
      // Invalid handle.
527
0
      return STATUS(InvalidArgument, "Invalid expression handle for constant");
528
0
    }
529
111
    down_cast<PgConstant*>(expr)->UpdateConstant(value, is_null);
530
111
    return Status::OK();
531
111
  }
yb::Status yb::pggate::PgApiImpl::UpdateConstant<long long>(yb::pggate::PgExpr*, long long, bool)
Line
Count
Source
524
1.02k
  CHECKED_STATUS UpdateConstant(PgExpr *expr, value_type value, bool is_null) {
525
1.02k
    if (expr->opcode() != PgExpr::Opcode::PG_EXPR_CONSTANT) {
526
      // Invalid handle.
527
0
      return STATUS(InvalidArgument, "Invalid expression handle for constant");
528
0
    }
529
1.02k
    down_cast<PgConstant*>(expr)->UpdateConstant(value, is_null);
530
1.02k
    return Status::OK();
531
1.02k
  }
yb::Status yb::pggate::PgApiImpl::UpdateConstant<float>(yb::pggate::PgExpr*, float, bool)
Line
Count
Source
524
43
  CHECKED_STATUS UpdateConstant(PgExpr *expr, value_type value, bool is_null) {
525
43
    if (expr->opcode() != PgExpr::Opcode::PG_EXPR_CONSTANT) {
526
      // Invalid handle.
527
0
      return STATUS(InvalidArgument, "Invalid expression handle for constant");
528
0
    }
529
43
    down_cast<PgConstant*>(expr)->UpdateConstant(value, is_null);
530
43
    return Status::OK();
531
43
  }
Unexecuted instantiation: yb::Status yb::pggate::PgApiImpl::UpdateConstant<double>(yb::pggate::PgExpr*, double, bool)
532
  CHECKED_STATUS UpdateConstant(PgExpr *expr, const char *value, bool is_null);
533
  CHECKED_STATUS UpdateConstant(PgExpr *expr, const void *value, int64_t bytes, bool is_null);
534
535
  // Operators.
536
  CHECKED_STATUS NewOperator(
537
      PgStatement *stmt, const char *opname, const YBCPgTypeEntity *type_entity,
538
      bool collate_is_valid_non_c, PgExpr **op_handle);
539
  CHECKED_STATUS OperatorAppendArg(PgExpr *op_handle, PgExpr *arg);
540
541
  // Foreign key reference caching.
542
  void DeleteForeignKeyReference(PgOid table_id, const Slice& ybctid);
543
  void AddForeignKeyReference(PgOid table_id, const Slice& ybctid);
544
  Result<bool> ForeignKeyReferenceExists(PgOid table_id, const Slice& ybctid, PgOid database_id);
545
  void AddForeignKeyReferenceIntent(PgOid table_id, const Slice& ybctid);
546
547
  // Sets the specified timeout in the rpc service.
548
  void SetTimeout(int timeout_ms);
549
550
  Result<client::TabletServersInfo> ListTabletServers();
551
552
  //------------------------------------------------------------------------------------------------
553
  // System Validation.
554
  CHECKED_STATUS ValidatePlacement(const char *placement_info);
555
556
 private:
557
  // Control variables.
558
  PggateOptions pggate_options_;
559
560
  // Metrics.
561
  std::unique_ptr<MetricRegistry> metric_registry_;
562
  scoped_refptr<MetricEntity> metric_entity_;
563
564
  // Memory tracker.
565
  std::shared_ptr<MemTracker> mem_tracker_;
566
567
  PgApiContext::MessengerHolder messenger_holder_;
568
569
  std::unique_ptr<rpc::ProxyCache> proxy_cache_;
570
571
  // TODO Rename to client_ when YBClient is removed.
572
  PgClient pg_client_;
573
574
  // TODO(neil) Map for environments (we should have just one ENV?). Environments should contain
575
  // all the custom flags the PostgreSQL sets. We ignore them all for now.
576
  PgEnv::SharedPtr pg_env_;
577
578
  scoped_refptr<server::HybridClock> clock_;
579
580
  // Local tablet-server shared memory segment handle.
581
  std::unique_ptr<tserver::TServerSharedObject> tserver_shared_object_;
582
583
  YBCPgCallbacks pg_callbacks_;
584
585
  scoped_refptr<PgTxnManager> pg_txn_manager_;
586
587
  // Mapping table of YugaByte and PostgreSQL datatypes.
588
  std::unordered_map<int, const YBCPgTypeEntity *> type_map_;
589
590
  scoped_refptr<PgSession> pg_session_;
591
};
592
593
}  // namespace pggate
594
}  // namespace yb
595
596
#endif // YB_YQL_PGGATE_PGGATE_H_