PostgreSQL Source Code: src/backend/optimizer/util/var.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

22

31

32

33typedef struct

34{

39

40typedef struct

41{

45

46typedef struct

47{

51

52typedef struct

53{

57

58typedef struct

59{

63

64typedef struct

65{

72

89 Var *oldvar);

91 Var *oldvar);

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

115{

117

118 context.varnos = NULL;

121

122

123

124

125

128 &context,

129 0);

130

131 return context.varnos;

132}

133

134

135

136

137

138

141{

143

144 context.varnos = NULL;

147

148

149

150

151

154 &context,

155 0);

156

157 return context.varnos;

158}

159

160static bool

162{

163 if (node == NULL)

164 return false;

166 {

167 Var *var = (Var *) node;

168

170 {

173 var->varnullingrels);

174 }

175 return false;

176 }

178 {

180

183 return false;

184 }

186 {

188

189

190

191

192

193

194

195

196

198 context->root != NULL)

199 {

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

218

220 {

221 if (phv->phid < context->root->placeholder_array_size)

222 phinfo = context->root->placeholder_array[phv->phid];

223 }

224 if (phinfo == NULL)

225 {

226

228 phv->phrels);

229 }

231 {

232

235 }

236 else

237 {

238

240 delta;

241

242

245

247 {

248

250 newevalat = bms_join(newevalat, delta);

251 }

253 newevalat);

254 }

255

256

257

258

259

260

263 return false;

264 }

265 }

267 {

268

269 bool result;

270

273 context, 0);

275 return result;

276 }

278}

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295void

297{

299

301 context.varno = varno;

302

304

306}

307

308static bool

310{

311 if (node == NULL)

312 return false;

314 {

315 Var *var = (Var *) node;

316

321 return false;

322 }

323

324

326

328}

329

330

331

332

333

334

335

336

337

340{

342

345

346

347

348

349

352 &context,

353 0);

354

355 return context.vars;

356}

357

358static bool

360{

361 if (node == NULL)

362 return false;

364 {

365 Var *var = (Var *) node;

366

369 return false;

370 }

372 {

374

377

378 return false;

379 }

381 {

382

383 bool result;

384

387 context, 0);

389 return result;

390 }

392}

393

394

395

396

397

398

399

400

401

402

403

404

405bool

407{

409}

410

411static bool

413{

414 if (node == NULL)

415 return false;

417 {

418 if (((Var *) node)->varlevelsup == 0)

419 return true;

420 return false;

421 }

423 return true;

425 {

427 return true;

428

429 }

431}

432

433

434

435

436

437

438

439

440

441

442

443bool

445{

446 int sublevels_up = levelsup;

447

450 &sublevels_up,

451 0);

452}

453

454static bool

456{

457 if (node == NULL)

458 return false;

460 {

461 if (((Var *) node)->varlevelsup == *sublevels_up)

462 return true;

463 return false;

464 }

466 {

467 if (*sublevels_up == 0)

468 return true;

469 return false;

470 }

472 {

473 if (((PlaceHolderVar *) node)->phlevelsup == *sublevels_up)

474 return true;

475

476 }

478 {

479

480 bool result;

481

482 (*sublevels_up)++;

485 sublevels_up,

486 0);

487 (*sublevels_up)--;

488 return result;

489 }

492 sublevels_up);

493}

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510bool

512{

514}

515

516static bool

518{

519 if (node == NULL)

520 return false;

522 {

523 if (((Var *) node)->varlevelsup == 0 &&

525 return true;

526 return false;

527 }

529 {

531 return true;

532 return false;

533 }

535 context);

536}

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554int

556{

558

559 context.var_location = -1;

561

564 &context,

565 0);

566

568}

569

570static bool

573{

574 if (node == NULL)

575 return false;

577 {

578 Var *var = (Var *) node;

579

582 {

584 return true;

585 }

586 return false;

587 }

589 {

590

591 return false;

592 }

593

595 {

596

597 bool result;

598

602 context,

603 0);

605 return result;

606 }

609 context);

610}

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

654{

656

657

664

666 context.flags = flags;

667

670}

671

672static bool

674{

675 if (node == NULL)

676 return false;

678 {

679 if (((Var *) node)->varlevelsup != 0)

680 elog(ERROR, "Upper-level Var found where not expected");

682 return false;

683 }

685 {

686 if (((Aggref *) node)->agglevelsup != 0)

687 elog(ERROR, "Upper-level Aggref found where not expected");

689 {

691

692 return false;

693 }

695 {

696

697 }

698 else

699 elog(ERROR, "Aggref found where not expected");

700 }

702 {

703 if (((GroupingFunc *) node)->agglevelsup != 0)

704 elog(ERROR, "Upper-level GROUPING found where not expected");

706 {

708

709 return false;

710 }

712 {

713

714 }

715 else

716 elog(ERROR, "GROUPING found where not expected");

717 }

719 {

720

722 {

724

725 return false;

726 }

728 {

729

730 }

731 else

732 elog(ERROR, "WindowFunc found where not expected");

733 }

735 {

737 elog(ERROR, "Upper-level PlaceHolderVar found where not expected");

739 {

741

742 return false;

743 }

745 {

746

747 }

748 else

749 elog(ERROR, "PlaceHolderVar found where not expected");

750 }

752}

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

790{

792

793

794

795

796

797

799

801 context.query = query;

803

805

807

809}

810

814{

815 if (node == NULL)

816 return NULL;

818 {

819 Var *var = (Var *) node;

821 Node *newvar;

822

823

825 return node;

828 return node;

830 {

831

837

839 forboth(lv, rte->joinaliasvars, ln, rte->eref->colnames)

840 {

842

843 if (newvar == NULL)

844 continue;

846

847

848

849

850

853

854 if (IsA(newvar, Var))

855 ((Var *) newvar)->location = var->location;

856

857

859 fields = lappend(fields, newvar);

860

862 }

864 rowexpr->args = fields;

865 rowexpr->row_typeid = var->vartype;

867

868 rowexpr->colnames = colnames;

870

871

873 var);

874 }

875

876

879 Assert(newvar != NULL);

881

882

883

884

885

888

889

890 if (IsA(newvar, Var))

891 ((Var *) newvar)->location = var->location;

892

893

895

896

899

900

902 }

904 {

905

907

910 context);

911

913 {

915 phv->phrels);

916

917 }

918 return (Node *) phv;

919 }

920

922 {

923

925 bool save_inserted_sublink;

926

932 context,

937 return (Node *) newnode;

938 }

939

942

946

948}

949

950

951

952

953

954

955

956

957

958

959

960

961

962

963

964

965

966

969{

971

972

973

974

975

976

978

980 context.query = query;

982

984

986

988}

989

993{

994 if (node == NULL)

995 return NULL;

997 {

998 Var *var = (Var *) node;

1000 Node *newvar;

1001

1002

1004 return node;

1007 return node;

1008

1009

1012 Assert(newvar != NULL);

1014

1015

1016

1017

1018

1021

1022

1023 if (IsA(newvar, Var))

1024 ((Var *) newvar)->location = var->location;

1025

1026

1029

1030

1032 }

1033

1035 {

1037

1038 if ((int) agg->agglevelsup == context->sublevels_up)

1039 {

1040

1041

1042

1043

1044

1045

1049

1050 return (Node *) agg;

1051 }

1052

1053

1054

1055

1056

1057

1058

1059 if ((int) agg->agglevelsup > context->sublevels_up)

1060 return node;

1061 }

1062

1064 {

1066

1067

1068

1069

1070

1072 return node;

1073 }

1074

1076 {

1077

1079 bool save_inserted_sublink;

1080

1086 context,

1091 return (Node *) newnode;

1092 }

1093

1095 context);

1096}

1097

1098

1099

1100

1101

1102static Node *

1104{

1106

1107 if (root == NULL)

1108 return newnode;

1109 if (oldvar->varnullingrels == NULL)

1110 return newnode;

1111

1114

1116

1118 {

1119

1120

1121

1122

1123

1124

1125

1126

1127

1129 relids,

1130 oldvar->varnullingrels);

1131 }

1132 else

1133 {

1134

1135

1136

1137

1138

1139

1140

1141

1142

1143

1146

1149 {

1152

1154 true, false);

1156

1158

1161 newnode = (Node *) newphv;

1162 }

1163 }

1164

1165 return newnode;

1166}

1167

1168

1169

1170

1171

1172static Node *

1174{

1175 if (oldvar->varnullingrels == NULL)

1176 return newnode;

1177

1180 else if (root)

1181 {

1182

1183

1184

1185

1186

1187

1188

1192

1193 if (bms_is_empty(phrels))

1194 {

1195 if (levelsup != 0)

1196 elog(ERROR, "unsupported join alias expression");

1198

1201 }

1203

1206 newnode = (Node *) newphv;

1207 }

1208 else

1209 {

1210

1211 elog(ERROR, "unsupported join alias expression");

1212 }

1213 return newnode;

1214}

1215

1216

1217

1218

1219

1220

1221

1222

1223

1224static bool

1226{

1227 if (newnode == NULL)

1228 return false;

1229 if (IsA(newnode, Var) &&

1230 ((Var *) newnode)->varlevelsup == oldvar->varlevelsup)

1231 return true;

1234 return true;

1236 {

1238

1239

1240

1241

1242

1243

1244

1245

1248 return false;

1249

1250

1251

1252

1253

1255 }

1257 {

1259

1260

1262 }

1264 {

1266

1267

1269 }

1271 {

1273

1274

1276 }

1278 {

1281

1283 foreach(lc, cexpr->args)

1284 {

1286 return false;

1287 }

1288 return true;

1289 }

1290 else

1291 return false;

1292}

1293

1294

1295

1296

1297

1298static void

1300{

1301 if (IsA(newnode, Var) &&

1302 ((Var *) newnode)->varlevelsup == oldvar->varlevelsup)

1303 {

1304 Var *newvar = (Var *) newnode;

1305

1306 newvar->varnullingrels = bms_add_members(newvar->varnullingrels,

1307 oldvar->varnullingrels);

1308 }

1311 {

1313

1315 oldvar->varnullingrels);

1316 }

1318 {

1320

1322 }

1324 {

1326

1328 }

1330 {

1332

1334 }

1336 {

1338

1340 }

1342 {

1345

1347 foreach(lc, cexpr->args)

1348 {

1350 }

1351 }

1352 else

1354}

1355

1356

1357

1358

1359

1362{

1363 Relids result = NULL;

1364 int rtindex;

1365

1366 rtindex = -1;

1367 while ((rtindex = bms_next_member(relids, rtindex)) >= 0)

1368 {

1370

1373 else

1375 }

1376 return result;

1377}

#define InvalidAttrNumber

Bitmapset * bms_difference(const Bitmapset *a, const Bitmapset *b)

Bitmapset * bms_make_singleton(int x)

bool bms_equal(const Bitmapset *a, const Bitmapset *b)

int bms_next_member(const Bitmapset *a, int prevbit)

Bitmapset * bms_del_member(Bitmapset *a, int x)

Bitmapset * bms_add_member(Bitmapset *a, int x)

Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)

Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)

Bitmapset * bms_copy(const Bitmapset *a)

bool contain_agg_clause(Node *clause)

bool contain_window_function(Node *clause)

bool contain_volatile_functions(Node *clause)

Assert(PointerIsAligned(start, uint64))

List * lappend(List *list, void *datum)

bool expression_returns_set(Node *clause)

#define expression_tree_mutator(n, m, c)

#define query_tree_walker(q, w, c, f)

#define query_or_expression_tree_walker(n, w, c, f)

#define QTW_IGNORE_GROUPEXPRS

#define expression_tree_walker(n, w, c)

#define query_tree_mutator(q, m, c, f)

#define QTW_IGNORE_JOINALIASES

#define IsA(nodeptr, _type_)

#define PVC_RECURSE_AGGREGATES

#define PVC_RECURSE_PLACEHOLDERS

#define PVC_RECURSE_WINDOWFUNCS

#define PVC_INCLUDE_WINDOWFUNCS

#define PVC_INCLUDE_PLACEHOLDERS

#define PVC_INCLUDE_AGGREGATES

#define rt_fetch(rangetable_index, rangetable)

static int list_length(const List *l)

#define forboth(cell1, list1, cell2, list2)

static void * list_nth(const List *list, int n)

PlaceHolderVar * make_placeholder_expr(PlannerInfo *root, Expr *expr, Relids phrels)

Relids get_relids_for_join(Query *query, int joinrelid)

Relids get_relids_in_jointree(Node *jtnode, bool include_outer_joins, bool include_inner_joins)

bool checkExprHasSubLink(Node *node)

Node * add_nulling_relids(Node *node, const Bitmapset *target_relids, const Bitmapset *added_relids)

void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up, int min_sublevels_up)

#define FirstLowInvalidHeapAttributeNumber

static bool pull_varattnos_walker(Node *node, pull_varattnos_context *context)

static Node * add_nullingrels_if_needed(PlannerInfo *root, Node *newnode, Var *oldvar)

bool contain_vars_of_level(Node *node, int levelsup)

Node * flatten_group_exprs(PlannerInfo *root, Query *query, Node *node)

static Node * flatten_join_alias_vars_mutator(Node *node, flatten_join_alias_vars_context *context)

bool contain_var_clause(Node *node)

Relids pull_varnos_of_level(PlannerInfo *root, Node *node, int levelsup)

Relids pull_varnos(PlannerInfo *root, Node *node)

static bool pull_varnos_walker(Node *node, pull_varnos_context *context)

static bool pull_var_clause_walker(Node *node, pull_var_clause_context *context)

static Node * flatten_group_exprs_mutator(Node *node, flatten_join_alias_vars_context *context)

List * pull_vars_of_level(Node *node, int levelsup)

List * pull_var_clause(Node *node, int flags)

static Relids alias_relid_set(Query *query, Relids relids)

static bool contain_vars_of_level_walker(Node *node, int *sublevels_up)

static bool contain_vars_returning_old_or_new_walker(Node *node, void *context)

Node * flatten_join_alias_vars(PlannerInfo *root, Query *query, Node *node)

static bool is_standard_join_alias_expression(Node *newnode, Var *oldvar)

static Node * mark_nullable_by_grouping(PlannerInfo *root, Node *newnode, Var *oldvar)

void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)

static void adjust_standard_join_alias_expression(Node *newnode, Var *oldvar)

static bool locate_var_of_level_walker(Node *node, locate_var_of_level_context *context)

int locate_var_of_level(Node *node, int levelsup)

bool contain_vars_returning_old_or_new(Node *node)

static bool contain_var_clause_walker(Node *node, void *context)

static bool pull_vars_walker(Node *node, pull_vars_context *context)