Skip to content

Commit 474a9ae

Browse files
committed
feat: full support for TupleTableSlot attributes
The penultimate commit introduced basic support to display attributes in TupleTableSlot, but it was only for pg 18. This commit adds support for missing versions. Also it adds tests for TupleTableSlot.
1 parent 6725ea4 commit 474a9ae

File tree

13 files changed

+1172
-58
lines changed

13 files changed

+1172
-58
lines changed

src/debugger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ export class CodeLLDBDebuggerFacade extends GenericDebuggerFacade {
11681168
}
11691169

11701170
async evaluate(expression: string, frameId: number | undefined, context?: string, noReturn?: boolean): Promise<dap.EvaluateResponse> {
1171+
/* TODO: handle 'is ambiguous' error - make another attempt */
11711172
try {
11721173
/*
11731174
* CodeLLDB has many expression evaluators: simple, python and native.

src/test/patches/pg10.22.patch

Lines changed: 105 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,25 @@ new file mode 100644
3535
index 00000000000..358d8795a48
3636
--- /dev/null
3737
+++ b/src/backend/optimizer/plan/vscodehelper.c
38-
@@ -0,0 +1,295 @@
38+
@@ -0,0 +1,396 @@
3939
+#include "postgres.h"
4040
+
41-
+#include "nodes/relation.h"
41+
+#include "access/tupdesc.h"
42+
+#include "access/htup_details.h"
43+
+#include "catalog/pg_type.h"
44+
+#include "executor/tuptable.h"
4245
+#include "nodes/bitmapset.h"
46+
+#include "nodes/primnodes.h"
47+
+#include "nodes/relation.h"
48+
+#include "utils/builtins.h"
4349
+#include "utils/hsearch.h"
50+
+#include "utils/rangetypes.h"
51+
+
52+
+extern void vscode_test_helper(PlannerInfo *root);
53+
+extern void vscode_test_helper_unused(void *pointer);
4454
+
45-
+#define UNUSED(x) ((void)x)
4655
+#define ARRAY_SIZE 16
56+
+#define UNUSED(x) ((void)x)
4757
+
4858
+typedef struct TestStructure
4959
+{
@@ -118,7 +128,6 @@ index 00000000000..358d8795a48
118128
+#define SH_DEFINE
119129
+#include "lib/simplehash.h"
120130
+
121-
+static Bitmapset *create_bms(void);
122131
+static HTAB *create_htab(void);
123132
+static testhash_hash *create_simplehash(void);
124133
+static List *create_custom_list(void);
@@ -235,6 +244,86 @@ index 00000000000..358d8795a48
235244
+ testhash_iterate(hash, &iterator);
236245
+}
237246
+
247+
+typedef void (*func_ptr)(void *);
248+
+
249+
+static TupleTableSlot *
250+
+create_tuple_table_slot(void)
251+
+{
252+
+ TupleTableSlot *slot;
253+
+ TupleDesc tupdesc;
254+
+
255+
+ /* (int, text, int4range) */
256+
+ tupdesc = CreateTemplateTupleDesc(3, false);
257+
+ TupleDescInitEntry(tupdesc, 1, "number", INT4OID, -1, 0);
258+
+ TupleDescInitEntry(tupdesc, 2, "string", TEXTOID, -1, 0);
259+
+ TupleDescInitEntry(tupdesc, 3, "range", INT4RANGEOID, -1, 0);
260+
+
261+
+ slot = MakeTupleTableSlot();
262+
+ ExecSetSlotDescriptor(slot, tupdesc);
263+
+ return slot;
264+
+}
265+
+
266+
+static void
267+
+fill_tuple_table_slot(TupleTableSlot *slot, int32 value, bool isnull_value,
268+
+ const char *text, bool isnull_text,
269+
+ int32 rangestart, int32 rangeend, bool isnull_range)
270+
+{
271+
+ MinimalTuple mintup;
272+
+ Datum values[3];
273+
+ bool isnull[3];
274+
+
275+
+ memset(isnull, false, sizeof(isnull));
276+
+ memset(values, 0, sizeof(values));
277+
+
278+
+ isnull[0] = isnull_value;
279+
+ isnull[1] = isnull_text;
280+
+ isnull[2] = isnull_range;
281+
+
282+
+ if (!isnull_value)
283+
+ {
284+
+ values[0] = Int32GetDatum(value);
285+
+ }
286+
+ if (!isnull_text)
287+
+ {
288+
+ values[1] = PointerGetDatum(cstring_to_text(text));
289+
+ }
290+
+ if (!isnull_range)
291+
+ {
292+
+ FmgrInfo fmgr;
293+
+ Oid makerangeoid;
294+
+ Const node;
295+
+
296+
+ makerangeoid = fmgr_internal_function("range_constructor2");
297+
+ fmgr_info(makerangeoid, &fmgr);
298+
+
299+
+ /* setup return type, so range_constructor2 can use it */
300+
+ node.xpr.type = T_Const;
301+
+ node.consttype = INT4RANGEOID;
302+
+ fmgr_info_set_expr((Node *)&node, &fmgr);
303+
+
304+
+ values[2] = FunctionCall2(&fmgr,
305+
+ Int32GetDatum(rangestart),
306+
+ Int32GetDatum(rangeend));
307+
+ }
308+
+
309+
+ mintup = heap_form_minimal_tuple(slot->tts_tupleDescriptor, values, isnull);
310+
+ ExecStoreMinimalTuple(mintup, slot, false);
311+
+}
312+
+
313+
+static TupleTableSlot *
314+
+create_tts(int32 value, bool isnull_value,
315+
+ const char *text, bool isnull_text,
316+
+ int32 rangestart, int32 rangeend, bool isnull_range)
317+
+{
318+
+ TupleTableSlot *slot;
319+
+
320+
+ slot = create_tuple_table_slot();
321+
+ fill_tuple_table_slot(slot, value, isnull_value, text, isnull_text,
322+
+ rangestart, rangeend, isnull_range);
323+
+ slot_getallattrs(slot);
324+
+ return slot;
325+
+}
326+
+
238327
+void
239328
+vscode_test_helper(PlannerInfo *root)
240329
+{
@@ -266,6 +355,12 @@ index 00000000000..358d8795a48
266355
+ List *int_list;
267356
+ RestrictInfo *rinfo;
268357
+ EquivalenceClass *eclass;
358+
+
359+
+ /* other special variables */
360+
+ TupleTableSlot *tts_all;
361+
+ TupleTableSlot *tts_null;
362+
+
363+
+ void (*some_ptr)(void *) = &vscode_test_helper_unused;
269364
+
270365
+ /* Protect against arbitrary query */
271366
+ if (!( list_length(root->parse->rtable) == 3
@@ -304,6 +399,9 @@ index 00000000000..358d8795a48
304399
+ structure_pointer_array[j]->value = j + 1;
305400
+ flexible_array_member->array[j] = j + 1;
306401
+ }
402+
+
403+
+ tts_all = create_tts(1, false, "hello", false, 2, 10, false);
404+
+ tts_null = create_tts(0, true, "world", false, 2, 10, false);
307405
+
308406
+ UNUSED(bms);
309407
+ UNUSED(node);
@@ -328,6 +426,9 @@ index 00000000000..358d8795a48
328426
+ UNUSED(flexible_array_member);
329427
+ UNUSED(custom_list);
330428
+ UNUSED(custom_list_variable);
429+
+ UNUSED(tts_all);
430+
+ UNUSED(tts_null);
431+
+ UNUSED(some_ptr);
331432
+
332433
+ return;
333434
+}

src/test/patches/pg11.22.patch

Lines changed: 102 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,25 @@ new file mode 100644
3535
index 00000000000..76f2903e179
3636
--- /dev/null
3737
+++ b/src/backend/optimizer/plan/vscodehelper.c
38-
@@ -0,0 +1,286 @@
38+
@@ -0,0 +1,384 @@
3939
+#include "postgres.h"
4040
+
41-
+#include "nodes/relation.h"
41+
+#include "access/tupdesc.h"
42+
+#include "access/htup_details.h"
43+
+#include "catalog/pg_type_d.h"
44+
+#include "executor/tuptable.h"
4245
+#include "nodes/bitmapset.h"
46+
+#include "nodes/primnodes.h"
47+
+#include "nodes/relation.h"
48+
+#include "utils/builtins.h"
4349
+#include "utils/hsearch.h"
50+
+#include "utils/rangetypes.h"
51+
+
52+
+extern void vscode_test_helper(PlannerInfo *root);
53+
+extern void vscode_test_helper_unused(void *pointer);
4454
+
45-
+#define UNUSED(x) ((void)x)
4655
+#define ARRAY_SIZE 16
56+
+#define UNUSED(x) ((void)x)
4757
+
4858
+typedef struct TestStructure
4959
+{
@@ -225,6 +235,82 @@ index 00000000000..76f2903e179
225235
+ testhash_iterate(hash, &iterator);
226236
+}
227237
+
238+
+typedef void (*func_ptr)(void *);
239+
+
240+
+static TupleTableSlot *
241+
+create_tuple_table_slot(void)
242+
+{
243+
+ TupleDesc tupdesc;
244+
+
245+
+ /* (int, text, int4range) */
246+
+ tupdesc = CreateTemplateTupleDesc(3, false);
247+
+ TupleDescInitEntry(tupdesc, 1, "number", INT4OID, -1, 0);
248+
+ TupleDescInitEntry(tupdesc, 2, "string", TEXTOID, -1, 0);
249+
+ TupleDescInitEntry(tupdesc, 3, "range", INT4RANGEOID, -1, 0);
250+
+
251+
+ return MakeTupleTableSlot(tupdesc);
252+
+}
253+
+
254+
+static void
255+
+fill_tuple_table_slot(TupleTableSlot *slot, int32 value, bool isnull_value,
256+
+ const char *text, bool isnull_text,
257+
+ int32 rangestart, int32 rangeend, bool isnull_range)
258+
+{
259+
+ MinimalTuple mintup;
260+
+ Datum values[3];
261+
+ bool isnull[3];
262+
+
263+
+ memset(isnull, false, sizeof(isnull));
264+
+ memset(values, 0, sizeof(values));
265+
+
266+
+ isnull[0] = isnull_value;
267+
+ isnull[1] = isnull_text;
268+
+ isnull[2] = isnull_range;
269+
+
270+
+ if (!isnull_value)
271+
+ {
272+
+ values[0] = Int32GetDatum(value);
273+
+ }
274+
+ if (!isnull_text)
275+
+ {
276+
+ values[1] = PointerGetDatum(cstring_to_text(text));
277+
+ }
278+
+ if (!isnull_range)
279+
+ {
280+
+ FmgrInfo fmgr;
281+
+ Oid makerangeoid;
282+
+ Const node;
283+
+
284+
+ makerangeoid = fmgr_internal_function("range_constructor2");
285+
+ fmgr_info(makerangeoid, &fmgr);
286+
+
287+
+ /* setup return type, so range_constructor2 can use it */
288+
+ node.xpr.type = T_Const;
289+
+ node.consttype = INT4RANGEOID;
290+
+ fmgr_info_set_expr((Node *)&node, &fmgr);
291+
+
292+
+ values[2] = FunctionCall2(&fmgr,
293+
+ Int32GetDatum(rangestart),
294+
+ Int32GetDatum(rangeend));
295+
+ }
296+
+
297+
+ mintup = heap_form_minimal_tuple(slot->tts_tupleDescriptor, values, isnull);
298+
+ ExecStoreMinimalTuple(mintup, slot, false);
299+
+}
300+
+
301+
+static TupleTableSlot *
302+
+create_tts(int32 value, bool isnull_value,
303+
+ const char *text, bool isnull_text,
304+
+ int32 rangestart, int32 rangeend, bool isnull_range)
305+
+{
306+
+ TupleTableSlot *slot;
307+
+
308+
+ slot = create_tuple_table_slot();
309+
+ fill_tuple_table_slot(slot, value, isnull_value, text, isnull_text,
310+
+ rangestart, rangeend, isnull_range);
311+
+ slot_getallattrs(slot);
312+
+ return slot;
313+
+}
228314
+
229315
+void
230316
+vscode_test_helper(PlannerInfo *root)
@@ -239,7 +325,7 @@ index 00000000000..76f2903e179
239325
+ TestPointerMember pointer_member;
240326
+ TestEmbeddedStructure embedded_member;
241327
+ TestFixedArray fixed_size_array_member;
242-
+
328+
+
243329
+ /* Config file */
244330
+ ArrayMember *array_member;
245331
+ ExprAlias expr_alias;
@@ -257,6 +343,12 @@ index 00000000000..76f2903e179
257343
+ List *int_list;
258344
+ RestrictInfo *rinfo;
259345
+ EquivalenceClass *eclass;
346+
+
347+
+ /* other special variables */
348+
+ TupleTableSlot *tts_all;
349+
+ TupleTableSlot *tts_null;
350+
+
351+
+ void (*some_ptr)(void *) = &vscode_test_helper_unused;
260352
+
261353
+ /* Protect against arbitrary query */
262354
+ if (!( list_length(root->parse->rtable) == 3
@@ -295,6 +387,9 @@ index 00000000000..76f2903e179
295387
+ structure_pointer_array[j]->value = j + 1;
296388
+ flexible_array_member->array[j] = j + 1;
297389
+ }
390+
+
391+
+ tts_all = create_tts(1, false, "hello", false, 2, 10, false);
392+
+ tts_null = create_tts(0, true, "world", false, 2, 10, false);
298393
+
299394
+ UNUSED(bms);
300395
+ UNUSED(node);
@@ -319,6 +414,9 @@ index 00000000000..76f2903e179
319414
+ UNUSED(flexible_array_member);
320415
+ UNUSED(custom_list);
321416
+ UNUSED(custom_list_variable);
417+
+ UNUSED(tts_all);
418+
+ UNUSED(tts_null);
419+
+ UNUSED(some_ptr);
322420
+
323421
+ return;
324422
+}

0 commit comments

Comments
 (0)