/*
 * This file and its contents are licensed under the Apache License 2.0.
 * Please see the included NOTICE for copyright information and
 * LICENSE-APACHE for a copy of the license.
 */
#pragma once

/*
 * This file contains source code that was copied and/or modified from
 * the PostgreSQL database, which is licensed under the open-source
 * PostgreSQL License. Please see the NOTICE at the top level
 * directory for a copy of the PostgreSQL License.
 *
 * These function were copied from the PostgreSQL core planner, since
 * they were declared static in the core planner, but we need them for
 * our manipulations.
 */

#include <postgres.h>
#include <nodes/execnodes.h>
#include <utils/rel.h>
#include <utils/selfuncs.h>

#include "export.h"

extern TSDLLEXPORT struct PathTarget *ts_make_partial_grouping_target(struct PlannerInfo *root,
																	  PathTarget *grouping_target);

extern bool ts_get_variable_range(PlannerInfo *root, VariableStatData *vardata, Oid sortop,
								  Datum *min, Datum *max);

extern TSDLLEXPORT PathKey *ts_make_pathkey_from_sortop(PlannerInfo *root, Expr *expr,
														Relids nullable_relids, Oid ordering_op,
														bool nulls_first, Index sortref,
														bool create_it);

#if PG18_GE
/* In PG18, child ems are not added to ec_members
 * but need to be maintained in separate Lists.
 *
 * https://github.com/postgres/postgres/commit/d69d45a5
 */
/* copied from add_child_eq_member */
extern TSDLLEXPORT void ts_add_child_eq_member(PlannerInfo *root, EquivalenceClass *ec,
											   EquivalenceMember *em, int child_relid);
#endif
