PostgreSQL Source Code: src/backend/commands/statscmds.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

16

41

42

46

47

48

49static int

51{

54

55

56 return (av - bv);

57}

58

59

60

61

64{

66 int nattnums = 0;

81 Oid relid;

84 Datum types[4];

92 int i;

95

97

98

99

100

101

102

103

107 errmsg("only a single relation is allowed in CREATE STATISTICS")));

108

109 foreach(cell, stmt->relations)

110 {

112

116 errmsg("only a single relation is allowed in CREATE STATISTICS")));

117

118

119

120

121

122

123

124

126

127

134 errmsg("cannot define statistics for relation \"%s\"",

137

138

139

140

141

142

143

144

148

149

153 errmsg("permission denied: \"%s\" is a system catalog",

155 }

156

159

160

161

162

163

164

165

166 if (stmt->defnames)

169 else

170 {

174 "stat",

176 }

178

179

180

181

182

184 {

186

192 }

193

194

195

196

200 {

201 if (stmt->if_not_exists)

202 {

203

204

205

206

209 errmsg("statistics object \"%s\" already exists, skipping",

213 }

214

217 errmsg("statistics object \"%s\" already exists", namestr)));

218 }

219

220

221

222

223

228 errmsg("cannot have more than %d columns in statistics",

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244 foreach(cell, stmt->exprs)

245 {

247

248 if (selem->name)

249 {

254

256

261 errmsg("column \"%s\" does not exist",

264

265

266 if (attForm->attnum <= 0)

269 errmsg("statistics creation on system columns is not supported")));

270

271

275 errmsg("statistics creation on virtual generated columns is not supported")));

276

277

282 errmsg("column \"%s\" cannot be used in statistics because its type %s has no default btree operator class",

284

285 attnums[nattnums] = attForm->attnum;

286 nattnums++;

288 }

289 else if (IsA(selem->expr, Var))

290 {

293

294

298 errmsg("statistics creation on system columns is not supported")));

299

300

304 errmsg("statistics creation on virtual generated columns is not supported")));

305

306

311 errmsg("column \"%s\" cannot be used in statistics because its type %s has no default btree operator class",

313

314 attnums[nattnums] = var->varattno;

315 nattnums++;

316 }

317 else

318 {

320 Oid atttype;

323 int k;

324

326

328

329 k = -1;

331 {

333

334

338 errmsg("statistics creation on system columns is not supported")));

339

340

344 errmsg("statistics creation on virtual generated columns is not supported")));

345 }

346

347

348

349

350

351

352

353

355 {

361 errmsg("expression cannot be used in multivariate statistics because its type %s has no default btree operator class",

363 }

364

366 }

367 }

368

369

370

371

372

373

374

375

377 {

378

379 if (stmt->stat_types != NIL)

382 errmsg("when building statistics on a single expression, statistics kinds may not be specified")));

383 }

384

385

389 foreach(cell, stmt->stat_types)

390 {

392

394 {

397 }

398 else if (strcmp(type, "dependencies") == 0)

399 {

402 }

404 {

407 }

408 else

411 errmsg("unrecognized statistics kind \"%s\"",

413 }

414

415

416

417

418

420 {

424 }

425

426

427

428

429

430

432

433

434

435

436

440 errmsg("extended statistics require at least 2 columns")));

441

442

443

444

445

446

448

449

450

451

452

453 for (i = 1; i < nattnums; i++)

454 {

455 if (attnums[i] == attnums[i - 1])

458 errmsg("duplicate column name in statistics definition")));

459 }

460

461

462

463

464

465

466

467

468

469

470

471

472

473

475 {

477 int cnt = 0;

478

480 {

482

484 cnt += 1;

485 }

486

487

489

490 if (cnt > 1)

493 errmsg("duplicate expression in statistics definition")));

494 }

495

496

498

499

511

512

514 {

516

520 }

521 else

523

525

526

527

528

530 memset(nulls, false, sizeof(nulls));

531

542

546

547

551

553

554

555

556

557

558

559

561

562

563

564

566

568

569

570

571

572

574

575

576 for (i = 0; i < nattnums; i++)

577 {

580 }

581

582

583

584

585

586

587

588

589

590

591

592

593 if (!nattnums)

594 {

597 }

598

599

600

601

602

606 relid,

609

610

611

612

613

614

617

619

620

621

622

623

624

625

626

627 if (stmt->stxcomment != NULL)

629 stmt->stxcomment);

630

631

633}

634

635

636

637

640{

651

652

653 if (stmt->stxstattarget && intVal(stmt->stxstattarget) != -1)

654 {

657 }

658 else

660

662 {

663

665 {

668 errmsg("statistics target %d is too low",

670 }

672 {

676 errmsg("lowering statistics target to %d",

678 }

679 }

680

681

683

684

685

686

687

688

690 {

691 char *schemaname;

693

695

697

698 if (schemaname)

700 (errmsg("statistics object \"%s.%s\" does not exist, skipping",

702 else

704 (errmsg("statistics object \"%s\" does not exist, skipping",

706

708 }

709

710

712

715 elog(ERROR, "cache lookup failed for extended statistics object %u", stxoid);

716

717

721

722

726

727

731 else

733

736

737

739

741

743

744

745

746

747

748

751

753

754 return address;

755}

756

757

758

759

760

761void

763{

766

768

771

772

774 {

776

778 }

779

781}

782

783

784

785

786void

788{

793 Oid relid;

794

795

796

797

798

800

802

804 elog(ERROR, "cache lookup failed for statistics object %u", statsOid);

805

807 relid = statext->stxrelid;

808

809

810

811

812

813

814

816

819

821

823

825

826

828

830}

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848static char *

851{

852 int pass = 0;

855

856

858

859 for (;;)

860 {

862

864

869 break;

870

871

874 }

875

877}

878

879

880

881

882

883

884

885

886

887

888

889

890static char *

892{

894 int buflen = 0;

896

897 buf[0] = '\0';

898 foreach(lc, exprs)

899 {

901 const char *name;

902

903

905 continue;

906

908

909 if (buflen > 0)

910 buf[buflen++] = '_';

911

912

913

914

915

916

917

919 name = "expr";

920

921

922

923

924

928 break;

929 }

931}

932

933

934

935

936

939{

942 Oid result;

943

946 {

947 if (missing_ok)

949 elog(ERROR, "cache lookup failed for statistics object %u", statId);

950 }

953

954 result = stx->stxrelid;

956 return result;

957}

void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)

AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)

bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)

ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)

int bms_next_member(const Bitmapset *a, int prevbit)

static Datum values[MAXATTR]

#define CStringGetTextDatum(s)

#define Assert(condition)

#define OidIsValid(objectId)

bool IsSystemRelation(Relation relation)

Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)

void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool reverse_self)

int errcode(int sqlerrcode)

#define ereport(elevel,...)

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

char * format_type_be(Oid type_oid)

bool allowSystemTableMods

HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)

HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)

void heap_freetuple(HeapTuple htup)

#define HeapTupleIsValid(tuple)

static void * GETSTRUCT(const HeapTupleData *tuple)

char * makeObjectName(const char *name1, const char *name2, const char *label)

void CatalogTupleUpdate(Relation heapRel, const ItemPointerData *otid, HeapTuple tup)

void CatalogTupleInsert(Relation heapRel, HeapTuple tup)

void CatalogTupleDelete(Relation heapRel, const ItemPointerData *tid)

int2vector * buildint2vector(const int16 *int2s, int n)

void CacheInvalidateRelcache(Relation relation)

void CacheInvalidateRelcacheByRelid(Oid relid)

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

#define ShareUpdateExclusiveLock

char get_attgenerated(Oid relid, AttrNumber attnum)

char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)

char * get_namespace_name(Oid nspid)

char * pstrdup(const char *in)

void pfree(void *pointer)

void namestrcpy(Name name, const char *str)

char * NameListToString(const List *names)

Oid QualifiedNameGetCreationNamespace(const List *names, char **objname_p)

Oid get_statistics_object_oid(List *names, bool missing_ok)

void DeconstructQualifiedName(const List *names, char **nspname_p, char **objname_p)

Oid exprType(const Node *expr)

#define IsA(nodeptr, _type_)

#define InvokeObjectPostCreateHook(classId, objectId, subId)

#define InvokeObjectPostAlterHook(classId, objectId, subId)

ObjectType get_relkind_objtype(char relkind)

const ObjectAddress InvalidObjectAddress

#define ObjectAddressSet(addr, class_id, object_id)

#define ObjectAddressSubSet(addr, class_id, object_id, object_sub_id)

char * nodeToString(const void *obj)

FormData_pg_attribute * Form_pg_attribute

int errdetail_relkind_not_supported(char relkind)

void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)

#define lfirst_node(type, lc)

static int list_length(const List *l)

void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)

END_CATALOG_STRUCT typedef FormData_pg_statistic_ext * Form_pg_statistic_ext

static char buf[DEFAULT_XLOG_SEG_SIZE]

#define qsort(a, b, c, d)

size_t strlcpy(char *dst, const char *src, size_t siz)

static Datum PointerGetDatum(const void *X)

static Datum Int16GetDatum(int16 X)

static Datum BoolGetDatum(bool X)

static Datum ObjectIdGetDatum(Oid X)

static Datum NameGetDatum(const NameData *X)

static Datum CStringGetDatum(const char *X)

static Datum CharGetDatum(char X)

#define RelationGetRelid(relation)

#define RelationGetDescr(relation)

#define RelationGetRelationName(relation)

#define RelationGetNamespace(relation)

void relation_close(Relation relation, LOCKMODE lockmode)

Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)

#define STATS_MAX_DIMENSIONS

ObjectAddress CreateStatistics(CreateStatsStmt *stmt, bool check_rights)

ObjectAddress AlterStatistics(AlterStatsStmt *stmt)

static char * ChooseExtendedStatisticNameAddition(List *exprs)

void RemoveStatisticsDataById(Oid statsOid, bool inh)

static char * ChooseExtendedStatisticName(const char *name1, const char *name2, const char *label, Oid namespaceid)

void RemoveStatisticsById(Oid statsOid)

static int compare_int16(const void *a, const void *b)

Oid StatisticsGetRelation(Oid statId, bool missing_ok)

#define ERRCODE_DUPLICATE_OBJECT

#define FirstLowInvalidHeapAttributeNumber

void ReleaseSysCache(HeapTuple tuple)

HeapTuple SearchSysCache2(SysCacheIdentifier cacheId, Datum key1, Datum key2)

HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)

HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)

#define SearchSysCacheExists2(cacheId, key1, key2)

#define GetSysCacheOid2(cacheId, oidcol, key1, key2)

void table_close(Relation relation, LOCKMODE lockmode)

Relation table_open(Oid relationId, LOCKMODE lockmode)

TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)

#define MAX_STATISTICS_TARGET

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