PostgreSQL Source Code: src/backend/optimizer/prep/prepagg.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

21

22

23

24

25

26

27

28

29

30

31

32

33

34

36

49#include "utils/fmgroids.h"

53

58 bool shareable,

60 int transtypeLen, bool transtypeByVal,

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

109void

114

115static void

117{

125 Oid aggtranstype;

126 int32 aggtranstypmod;

127 int32 aggtransspace;

128 bool shareable;

129 int aggno;

130 int transno;

132 int16 resulttypeLen;

133 bool resulttypeByVal;

136 bool initValueIsNull;

137 bool transtypeByVal;

138 int16 transtypeLen;

140 int numArguments;

141

142 Assert(aggref->agglevelsup == 0);

143

144

145

146

147

148

152 elog(ERROR, "cache lookup failed for aggregate %u",

160 aggtranstype = aggform->aggtranstype;

161 aggtransspace = aggform->aggtransspace;

162

163

164

165

166

167

169

170

172 aggtranstype,

174 numArguments);

175 aggref->aggtranstype = aggtranstype;

176

177

178

179

180

181

182 aggtranstypmod = -1;

183 if (aggref->args)

184 {

186

189 }

190

191

192

193

194

195

196

197

198

199

201

202

204 &resulttypeLen,

205 &resulttypeByVal);

206

207

210 &initValueIsNull);

211 if (initValueIsNull)

213 else

215

217

218

219

220

221

223 if (aggno != -1)

224 {

226

228 transno = agginfo->transno;

229 }

230 else

231 {

233

236 agginfo->shareable = shareable;

237

240

241

242

243

244

245

247 {

248 root->numOrderedAggs++;

249 root->hasNonPartialAggs = true;

250 }

251

253 &transtypeLen,

254 &transtypeByVal);

255

256

257

258

259

262 transtypeLen, transtypeByVal,

267 if (transno == -1)

268 {

270

277 transinfo->aggtranstype = aggtranstype;

278 transinfo->aggtranstypmod = aggtranstypmod;

279 transinfo->transtypeLen = transtypeLen;

280 transinfo->transtypeByVal = transtypeByVal;

281 transinfo->aggtransspace = aggtransspace;

283 transinfo->initValueIsNull = initValueIsNull;

284

287

288

289

290

291

292 if (root->hasNonPartialAggs)

293 {

294

295

296

297

299 root->hasNonPartialAggs = true;

300

301

302

303

304

305

306

308 {

309

312 root->hasNonSerialAggs = true;

313

314

315

316

317

318

319

320

321

322

323

324

325

329 root->hasNonSerialAggs = true;

330 }

331 }

332 }

333 agginfo->transno = transno;

334 }

335

336

337

338

339 aggref->aggno = aggno;

340 aggref->aggtransno = transno;

341}

342

343static bool

345{

346 if (node == NULL)

347 return false;

349 {

351

353

354

355

356

357

358

359 return false;

360 }

363}

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378static int

381{

383 int aggno;

384

386

387

389 return -1;

390

391

392

393

394

395

396

397

398

399

400 aggno = -1;

401 foreach(lc, root->agginfos)

402 {

405

406 aggno++;

407

409

410

420 continue;

421

422

427 {

430 return aggno;

431 }

432

433

434

435

436

437

438

439

443 }

444

445 return -1;

446}

447

448

449

450

451

452

453

454

455

456static int

459 int transtypeLen, bool transtypeByVal,

464{

466

467

468 if (!shareable)

469 return -1;

470

472 {

475 root->aggtransinfos,

476 transno);

477

478

479

480

481

484 continue;

485

486

487

488

489

490

491

492

495 continue;

496

497

498

499

500

501

502

504 continue;

505

506

507

508

510 return transno;

511

514 transtypeByVal, transtypeLen))

515 return transno;

516 }

517 return -1;

518}

519

522{

524 typioparam;

527

531 typioparam, -1);

534}

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558void

560{

562

563 foreach(lc, root->aggtransinfos)

564 {

566

567

568

569

570

572 {

573

576 }

577 else

588

589

590

591

592

594 {

595

597

601

602

603

604

605

606

607

608

610 {

615 }

616 }

617

618

619

620

621

622

623

625 {

627

628

629 if (transinfo->aggtransspace > 0)

632 {

633

634

635

636

637

638

640 }

641 else

642 {

644 }

645

648 }

650 {

651

652

653

654

655

656

657

658

659

660 if (transinfo->aggtransspace > 0)

662 else

664 }

665 }

666

667 foreach(lc, root->agginfos)

668 {

671

672

673

674

675

680

681

682

683

684

686 {

688

693 }

694 }

695}

#define TextDatumGetCString(d)

#define Assert(condition)

#define OidIsValid(objectId)

bool contain_volatile_functions(Node *clause)

void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)

bool datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen)

bool equal(const void *a, const void *b)

Datum OidInputFunctionCall(Oid functionId, char *str, Oid typioparam, int32 typmod)

#define HeapTupleIsValid(tuple)

static void * GETSTRUCT(const HeapTupleData *tuple)

static int initValue(long lng_val)

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

List * lappend_int(List *list, int datum)

void list_free(List *list)

void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)

void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)

int32 get_typavgwidth(Oid typid, int32 typmod)

void pfree(void *pointer)

#define ALLOCSET_SMALL_INITSIZE

#define ALLOCSET_DEFAULT_INITSIZE

Oid exprType(const Node *expr)

int32 exprTypmod(const Node *expr)

#define expression_tree_walker(n, w, c)

#define DO_AGGSPLIT_SKIPFINAL(as)

#define IsA(nodeptr, _type_)

#define DO_AGGSPLIT_DESERIALIZE(as)

#define DO_AGGSPLIT_COMBINE(as)

#define DO_AGGSPLIT_SERIALIZE(as)

Oid resolve_aggregate_transtype(Oid aggfuncid, Oid aggtranstype, Oid *inputTypes, int numArguments)

bool agg_args_support_sendreceive(Aggref *aggref)

int get_aggregate_argtypes(Aggref *aggref, Oid *inputTypes)

END_CATALOG_STRUCT typedef FormData_pg_aggregate * Form_pg_aggregate

#define lfirst_node(type, lc)

static int list_length(const List *l)

#define linitial_node(type, l)

#define list_nth_node(type, list, n)

void add_function_cost(PlannerInfo *root, Oid funcid, Node *node, QualCost *cost)

static Datum ObjectIdGetDatum(Oid X)

static bool preprocess_aggrefs_walker(Node *node, PlannerInfo *root)

static Datum GetAggInitVal(Datum textInitVal, Oid transtype)

void get_agg_clause_costs(PlannerInfo *root, AggSplit aggsplit, AggClauseCosts *costs)

static int find_compatible_agg(PlannerInfo *root, Aggref *newagg, List **same_input_transnos)

static int find_compatible_trans(PlannerInfo *root, Aggref *newagg, bool shareable, Oid aggtransfn, Oid aggtranstype, int transtypeLen, bool transtypeByVal, Oid aggcombinefn, Oid aggserialfn, Oid aggdeserialfn, Datum initValue, bool initValueIsNull, List *transnos)

static void preprocess_aggref(Aggref *aggref, PlannerInfo *root)

void preprocess_aggrefs(PlannerInfo *root, Node *clause)

void ReleaseSysCache(HeapTuple tuple)

HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)

Datum SysCacheGetAttr(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)