Skip to content

Commit 77db132

Browse files
committed
Remove debug_print_rel and replace usages with pprint
Going by c4a1933, b33ef39 and 0589371 (to name just a few), it seems that maintaining debug_print_rel() is often forgotten. In the case of c4a1933, it was several years before anyone noticed that a path type was not handled by debug_print_rel(). (debug_print_rel() is only compiled when building with OPTIMIZER_DEBUG). After a quick survey on the pgsql-hackers mailing list, nobody came forward to admit that they use OPTIMIZER_DEBUG. So to prevent any future maintenance neglect, let's just remove debug_print_rel() and have OPTIMIZER_DEBUG make use of pprint() instead (as suggested by Tom Lane). If anyone wants to come forward to claim they make use of OPTIMIZER_DEBUG in a way that they need debug_print_rel() then they have around 10 months remaining in the v17 cycle where we could revert this. If nobody comes forward in that time, then we can likely safely declare debug_print_rel() as not worth keeping. Discussion: https://postgr.es/m/CAApHDvoCdjo8Cu2zEZF4-AxWG-90S+pYXAnoDDa9J3xH-OrczQ@mail.gmail.com
1 parent 82a7132 commit 77db132

File tree

2 files changed

+3
-329
lines changed

2 files changed

+3
-329
lines changed

src/backend/optimizer/path/allpaths.c

Lines changed: 3 additions & 325 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
563563
set_cheapest(rel);
564564

565565
#ifdef OPTIMIZER_DEBUG
566-
debug_print_rel(root, rel);
566+
pprint(rel);
567567
#endif
568568
}
569569

@@ -3504,7 +3504,7 @@ standard_join_search(PlannerInfo *root, int levels_needed, List *initial_rels)
35043504
set_cheapest(rel);
35053505

35063506
#ifdef OPTIMIZER_DEBUG
3507-
debug_print_rel(root, rel);
3507+
pprint(rel);
35083508
#endif
35093509
}
35103510
}
@@ -4372,7 +4372,7 @@ generate_partitionwise_join_paths(PlannerInfo *root, RelOptInfo *rel)
43724372
continue;
43734373

43744374
#ifdef OPTIMIZER_DEBUG
4375-
debug_print_rel(root, child_rel);
4375+
pprint(child_rel);
43764376
#endif
43774377

43784378
live_children = lappend(live_children, child_rel);
@@ -4389,325 +4389,3 @@ generate_partitionwise_join_paths(PlannerInfo *root, RelOptInfo *rel)
43894389
add_paths_to_append_rel(root, rel, live_children);
43904390
list_free(live_children);
43914391
}
4392-
4393-
4394-
/*****************************************************************************
4395-
* DEBUG SUPPORT
4396-
*****************************************************************************/
4397-
4398-
#ifdef OPTIMIZER_DEBUG
4399-
4400-
static void
4401-
print_relids(PlannerInfo *root, Relids relids)
4402-
{
4403-
int x;
4404-
bool first = true;
4405-
4406-
x = -1;
4407-
while ((x = bms_next_member(relids, x)) >= 0)
4408-
{
4409-
if (!first)
4410-
printf(" ");
4411-
if (x < root->simple_rel_array_size &&
4412-
root->simple_rte_array[x])
4413-
printf("%s", root->simple_rte_array[x]->eref->aliasname);
4414-
else
4415-
printf("%d", x);
4416-
first = false;
4417-
}
4418-
}
4419-
4420-
static void
4421-
print_restrictclauses(PlannerInfo *root, List *clauses)
4422-
{
4423-
ListCell *l;
4424-
4425-
foreach(l, clauses)
4426-
{
4427-
RestrictInfo *c = lfirst(l);
4428-
4429-
print_expr((Node *) c->clause, root->parse->rtable);
4430-
if (lnext(clauses, l))
4431-
printf(", ");
4432-
}
4433-
}
4434-
4435-
static void
4436-
print_path(PlannerInfo *root, Path *path, int indent)
4437-
{
4438-
const char *ptype;
4439-
bool join = false;
4440-
Path *subpath = NULL;
4441-
int i;
4442-
4443-
switch (nodeTag(path))
4444-
{
4445-
case T_Path:
4446-
switch (path->pathtype)
4447-
{
4448-
case T_SeqScan:
4449-
ptype = "SeqScan";
4450-
break;
4451-
case T_SampleScan:
4452-
ptype = "SampleScan";
4453-
break;
4454-
case T_FunctionScan:
4455-
ptype = "FunctionScan";
4456-
break;
4457-
case T_TableFuncScan:
4458-
ptype = "TableFuncScan";
4459-
break;
4460-
case T_ValuesScan:
4461-
ptype = "ValuesScan";
4462-
break;
4463-
case T_CteScan:
4464-
ptype = "CteScan";
4465-
break;
4466-
case T_NamedTuplestoreScan:
4467-
ptype = "NamedTuplestoreScan";
4468-
break;
4469-
case T_Result:
4470-
ptype = "Result";
4471-
break;
4472-
case T_WorkTableScan:
4473-
ptype = "WorkTableScan";
4474-
break;
4475-
default:
4476-
ptype = "???Path";
4477-
break;
4478-
}
4479-
break;
4480-
case T_IndexPath:
4481-
ptype = "IdxScan";
4482-
break;
4483-
case T_BitmapHeapPath:
4484-
ptype = "BitmapHeapScan";
4485-
break;
4486-
case T_BitmapAndPath:
4487-
ptype = "BitmapAndPath";
4488-
break;
4489-
case T_BitmapOrPath:
4490-
ptype = "BitmapOrPath";
4491-
break;
4492-
case T_TidPath:
4493-
ptype = "TidScan";
4494-
break;
4495-
case T_TidRangePath:
4496-
ptype = "TidRangePath";
4497-
break;
4498-
case T_SubqueryScanPath:
4499-
ptype = "SubqueryScan";
4500-
break;
4501-
case T_ForeignPath:
4502-
ptype = "ForeignScan";
4503-
break;
4504-
case T_CustomPath:
4505-
ptype = "CustomScan";
4506-
break;
4507-
case T_NestPath:
4508-
ptype = "NestLoop";
4509-
join = true;
4510-
break;
4511-
case T_MergePath:
4512-
ptype = "MergeJoin";
4513-
join = true;
4514-
break;
4515-
case T_HashPath:
4516-
ptype = "HashJoin";
4517-
join = true;
4518-
break;
4519-
case T_AppendPath:
4520-
ptype = "Append";
4521-
break;
4522-
case T_MergeAppendPath:
4523-
ptype = "MergeAppend";
4524-
break;
4525-
case T_GroupResultPath:
4526-
ptype = "GroupResult";
4527-
break;
4528-
case T_MaterialPath:
4529-
ptype = "Material";
4530-
subpath = ((MaterialPath *) path)->subpath;
4531-
break;
4532-
case T_MemoizePath:
4533-
ptype = "Memoize";
4534-
subpath = ((MemoizePath *) path)->subpath;
4535-
break;
4536-
case T_UniquePath:
4537-
ptype = "Unique";
4538-
subpath = ((UniquePath *) path)->subpath;
4539-
break;
4540-
case T_GatherPath:
4541-
ptype = "Gather";
4542-
subpath = ((GatherPath *) path)->subpath;
4543-
break;
4544-
case T_GatherMergePath:
4545-
ptype = "GatherMerge";
4546-
subpath = ((GatherMergePath *) path)->subpath;
4547-
break;
4548-
case T_ProjectionPath:
4549-
ptype = "Projection";
4550-
subpath = ((ProjectionPath *) path)->subpath;
4551-
break;
4552-
case T_ProjectSetPath:
4553-
ptype = "ProjectSet";
4554-
subpath = ((ProjectSetPath *) path)->subpath;
4555-
break;
4556-
case T_SortPath:
4557-
ptype = "Sort";
4558-
subpath = ((SortPath *) path)->subpath;
4559-
break;
4560-
case T_IncrementalSortPath:
4561-
ptype = "IncrementalSort";
4562-
subpath = ((SortPath *) path)->subpath;
4563-
break;
4564-
case T_GroupPath:
4565-
ptype = "Group";
4566-
subpath = ((GroupPath *) path)->subpath;
4567-
break;
4568-
case T_UpperUniquePath:
4569-
ptype = "UpperUnique";
4570-
subpath = ((UpperUniquePath *) path)->subpath;
4571-
break;
4572-
case T_AggPath:
4573-
ptype = "Agg";
4574-
subpath = ((AggPath *) path)->subpath;
4575-
break;
4576-
case T_GroupingSetsPath:
4577-
ptype = "GroupingSets";
4578-
subpath = ((GroupingSetsPath *) path)->subpath;
4579-
break;
4580-
case T_MinMaxAggPath:
4581-
ptype = "MinMaxAgg";
4582-
break;
4583-
case T_WindowAggPath:
4584-
ptype = "WindowAgg";
4585-
subpath = ((WindowAggPath *) path)->subpath;
4586-
break;
4587-
case T_SetOpPath:
4588-
ptype = "SetOp";
4589-
subpath = ((SetOpPath *) path)->subpath;
4590-
break;
4591-
case T_RecursiveUnionPath:
4592-
ptype = "RecursiveUnion";
4593-
break;
4594-
case T_LockRowsPath:
4595-
ptype = "LockRows";
4596-
subpath = ((LockRowsPath *) path)->subpath;
4597-
break;
4598-
case T_ModifyTablePath:
4599-
ptype = "ModifyTable";
4600-
break;
4601-
case T_LimitPath:
4602-
ptype = "Limit";
4603-
subpath = ((LimitPath *) path)->subpath;
4604-
break;
4605-
default:
4606-
ptype = "???Path";
4607-
break;
4608-
}
4609-
4610-
for (i = 0; i < indent; i++)
4611-
printf("\t");
4612-
printf("%s", ptype);
4613-
4614-
if (path->parent)
4615-
{
4616-
printf("(");
4617-
print_relids(root, path->parent->relids);
4618-
printf(")");
4619-
}
4620-
if (path->param_info)
4621-
{
4622-
printf(" required_outer (");
4623-
print_relids(root, path->param_info->ppi_req_outer);
4624-
printf(")");
4625-
}
4626-
printf(" rows=%.0f cost=%.2f..%.2f\n",
4627-
path->rows, path->startup_cost, path->total_cost);
4628-
4629-
if (path->pathkeys)
4630-
{
4631-
for (i = 0; i < indent; i++)
4632-
printf("\t");
4633-
printf(" pathkeys: ");
4634-
print_pathkeys(path->pathkeys, root->parse->rtable);
4635-
}
4636-
4637-
if (join)
4638-
{
4639-
JoinPath *jp = (JoinPath *) path;
4640-
4641-
for (i = 0; i < indent; i++)
4642-
printf("\t");
4643-
printf(" clauses: ");
4644-
print_restrictclauses(root, jp->joinrestrictinfo);
4645-
printf("\n");
4646-
4647-
if (IsA(path, MergePath))
4648-
{
4649-
MergePath *mp = (MergePath *) path;
4650-
4651-
for (i = 0; i < indent; i++)
4652-
printf("\t");
4653-
printf(" sortouter=%d sortinner=%d materializeinner=%d\n",
4654-
((mp->outersortkeys) ? 1 : 0),
4655-
((mp->innersortkeys) ? 1 : 0),
4656-
((mp->materialize_inner) ? 1 : 0));
4657-
}
4658-
4659-
print_path(root, jp->outerjoinpath, indent + 1);
4660-
print_path(root, jp->innerjoinpath, indent + 1);
4661-
}
4662-
4663-
if (subpath)
4664-
print_path(root, subpath, indent + 1);
4665-
}
4666-
4667-
void
4668-
debug_print_rel(PlannerInfo *root, RelOptInfo *rel)
4669-
{
4670-
ListCell *l;
4671-
4672-
printf("RELOPTINFO (");
4673-
print_relids(root, rel->relids);
4674-
printf("): rows=%.0f width=%d\n", rel->rows, rel->reltarget->width);
4675-
4676-
if (rel->baserestrictinfo)
4677-
{
4678-
printf("\tbaserestrictinfo: ");
4679-
print_restrictclauses(root, rel->baserestrictinfo);
4680-
printf("\n");
4681-
}
4682-
4683-
if (rel->joininfo)
4684-
{
4685-
printf("\tjoininfo: ");
4686-
print_restrictclauses(root, rel->joininfo);
4687-
printf("\n");
4688-
}
4689-
4690-
printf("\tpath list:\n");
4691-
foreach(l, rel->pathlist)
4692-
print_path(root, lfirst(l), 1);
4693-
if (rel->cheapest_parameterized_paths)
4694-
{
4695-
printf("\n\tcheapest parameterized paths:\n");
4696-
foreach(l, rel->cheapest_parameterized_paths)
4697-
print_path(root, lfirst(l), 1);
4698-
}
4699-
if (rel->cheapest_startup_path)
4700-
{
4701-
printf("\n\tcheapest startup path:\n");
4702-
print_path(root, rel->cheapest_startup_path, 1);
4703-
}
4704-
if (rel->cheapest_total_path)
4705-
{
4706-
printf("\n\tcheapest total path:\n");
4707-
print_path(root, rel->cheapest_total_path, 1);
4708-
}
4709-
printf("\n");
4710-
fflush(stdout);
4711-
}
4712-
4713-
#endif /* OPTIMIZER_DEBUG */

src/include/optimizer/paths.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ extern void create_partial_bitmap_paths(PlannerInfo *root, RelOptInfo *rel,
6363
extern void generate_partitionwise_join_paths(PlannerInfo *root,
6464
RelOptInfo *rel);
6565

66-
#ifdef OPTIMIZER_DEBUG
67-
extern void debug_print_rel(PlannerInfo *root, RelOptInfo *rel);
68-
#endif
69-
7066
/*
7167
* indxpath.c
7268
* routines to generate index paths

0 commit comments

Comments
 (0)