Skip to content

Commit 1fed28e

Browse files
authored
Tidy up and remove redundant json output path (#4)
* Tidy up of commented out code and remove debug print statements * tidy postgres.c * Remove DestDebugJson output
1 parent 701568c commit 1fed28e

File tree

21 files changed

+174
-251
lines changed

21 files changed

+174
-251
lines changed

src/backend/access/common/printtup.c

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@
1919
#include "libpq/libpq.h"
2020
#include "libpq/pqformat.h"
2121
#include "tcop/pquery.h"
22-
#include "utils/json.h"
2322
#include "utils/lsyscache.h"
2423
#include "utils/memdebug.h"
2524
#include "utils/memutils.h"
2625

27-
#ifdef EMSCRIPTEN
28-
#include <emscripten.h>
29-
#endif
3026

3127
static void printtup_startup(DestReceiver *self, int operation,
3228
TupleDesc typeinfo);
@@ -487,84 +483,3 @@ debugtup(TupleTableSlot *slot, DestReceiver *self)
487483

488484
return true;
489485
}
490-
491-
/* ----------------------------------------------------------------
492-
* printtup json
493-
* ----------------------------------------------------------------
494-
*/
495-
496-
StringInfoData json_result;
497-
498-
#ifdef EMSCRIPTEN
499-
EM_JS(void, dispatch_result, (char *res), {
500-
// Dispatch the result to JS land
501-
var query_result = UTF8ToString(res);
502-
var event = new Module.Event("result", {
503-
detail: { result: query_result },
504-
});
505-
Module.eventTarget.dispatchEvent(event);
506-
});
507-
#endif
508-
509-
void
510-
debugtup_json_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
511-
{
512-
MemoryContext oldcxt = MemoryContextSwitchTo(TopMemoryContext);
513-
514-
if (!json_result.data)
515-
initStringInfo(&json_result);
516-
else
517-
resetStringInfo(&json_result);
518-
519-
appendStringInfoChar(&json_result, '[');
520-
521-
MemoryContextSwitchTo(oldcxt);
522-
}
523-
524-
bool
525-
debugtup_json(TupleTableSlot *slot, DestReceiver *self)
526-
{
527-
TupleDesc tupdesc = slot->tts_tupleDescriptor;
528-
int i;
529-
bool needsep = false;
530-
531-
/* without tuples json_result contain only '[', so len is 1 */
532-
if (json_result.len > 1)
533-
appendStringInfoChar(&json_result, ',');
534-
535-
appendStringInfoChar(&json_result, '{');
536-
537-
for (i = 0; i < tupdesc->natts; i++)
538-
{
539-
Datum val;
540-
bool isnull;
541-
char *attname;
542-
Form_pg_attribute att = TupleDescAttr(tupdesc, i);
543-
544-
if (att->attisdropped)
545-
continue;
546-
547-
if (needsep)
548-
appendStringInfoString(&json_result, ",");
549-
needsep = true;
550-
551-
attname = NameStr(att->attname);
552-
escape_json(&json_result, attname);
553-
appendStringInfoChar(&json_result, ':');
554-
555-
val = slot_getattr(slot, i + 1, &isnull);
556-
add_json(val, isnull, &json_result, att->atttypid, false);
557-
}
558-
559-
appendStringInfoChar(&json_result, '}');
560-
561-
return true;
562-
}
563-
564-
void
565-
debugtup_json_shutdown(DestReceiver *self)
566-
{
567-
appendStringInfoChar(&json_result, ']');
568-
appendStringInfoChar(&json_result, '\0');
569-
dispatch_result(json_result.data);
570-
}

src/backend/access/transam/slru.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,8 +1557,6 @@ SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, void *data)
15571557
int segno;
15581558
int segpage;
15591559

1560-
elog(LOG, "! SlruScanDirectory start %s, %s", getcwd(NULL, 100), ctl->Dir);
1561-
15621560
cldir = AllocateDir(ctl->Dir);
15631561
while ((clde = ReadDir(cldir, ctl->Dir)) != NULL)
15641562
{
@@ -1572,7 +1570,7 @@ SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, void *data)
15721570
segno = (int) strtol(clde->d_name, NULL, 16);
15731571
segpage = segno * SLRU_PAGES_PER_SEGMENT;
15741572

1575-
elog(LOG, "SlruScanDirectory invoking callback on %s/%s",
1573+
elog(DEBUG2, "SlruScanDirectory invoking callback on %s/%s",
15761574
ctl->Dir, clde->d_name);
15771575
retval = callback(ctl, clde->d_name, segpage, data);
15781576
if (retval)
@@ -1581,8 +1579,6 @@ SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, void *data)
15811579
}
15821580
FreeDir(cldir);
15831581

1584-
elog(LOG, "! SlruScanDirectory stop");
1585-
15861582
return retval;
15871583
}
15881584

src/backend/main/main.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ main(int argc, char *argv[])
6363
{
6464
bool do_check_root = true;
6565

66-
printf("Hey-hey!\n");
67-
6866
/*
6967
* If supported on the current platform, set up a handler to be called if
7068
* the backend/postmaster crashes with a fatal signal or exception.

src/backend/nodes/nodeFuncs.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4000,32 +4000,24 @@ planstate_tree_walker(PlanState *planstate,
40004000
/* Guard against stack overflow due to overly complex plan trees */
40014001
check_stack_depth();
40024002

4003-
// printf("planstate_tree_walker1\n");
4004-
40054003
/* initPlan-s */
40064004
if (planstate_walk_subplans(planstate->initPlan, walker, context))
40074005
return true;
40084006

4009-
// printf("planstate_tree_walker2\n");
4010-
40114007
/* lefttree */
40124008
if (outerPlanState(planstate))
40134009
{
40144010
if (walker(outerPlanState(planstate), context))
40154011
return true;
40164012
}
40174013

4018-
// printf("planstate_tree_walker3\n");
4019-
40204014
/* righttree */
40214015
if (innerPlanState(planstate))
40224016
{
40234017
if (walker(innerPlanState(planstate), context))
40244018
return true;
40254019
}
40264020

4027-
// printf("planstate_tree_walker4\n");
4028-
40294021
/* special child plans */
40304022
switch (nodeTag(plan))
40314023
{

src/backend/port/sysv_shmem.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ PGSharedMemoryCreate(Size size,
657657
struct stat statbuf;
658658
Size sysvsize;
659659

660-
elog(NOTICE, "! Hacky way to init shared memory");
660+
elog(NOTICE, "Init WASM shared memory");
661661

662662
/* Initialize new segment. */
663663
hdr = (PGShmemHeader *) malloc(size);
@@ -691,9 +691,6 @@ PGSharedMemoryCreate(Size size,
691691
memcpy(AnonymousShmem, hdr, sizeof(PGShmemHeader));
692692
return (PGShmemHeader *) AnonymousShmem;
693693

694-
695-
696-
697694
/*
698695
* We use the data directory's ID info (inode and device numbers) to
699696
* positively identify shmem segments associated with this data dir, and

src/backend/postmaster/postmaster.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,22 +1501,24 @@ getInstallationPaths(const char *argv0)
15011501
*/
15021502
get_pkglib_path(my_exec_path, pkglib_path);
15031503

1504-
// /*
1505-
// * Verify that there's a readable directory there; otherwise the Postgres
1506-
// * installation is incomplete or corrupt. (A typical cause of this
1507-
// * failure is that the postgres executable has been moved or hardlinked to
1508-
// * some directory that's not a sibling of the installation lib/
1509-
// * directory.)
1510-
// */
1511-
// pdir = AllocateDir(pkglib_path);
1512-
// if (pdir == NULL)
1513-
// ereport(ERROR,
1514-
// (errcode_for_file_access(),
1515-
// errmsg("could not open directory \"%s\": %m",
1516-
// pkglib_path),
1517-
// errhint("This may indicate an incomplete PostgreSQL installation, or that the file \"%s\" has been moved away from its proper location.",
1518-
// my_exec_path)));
1519-
// FreeDir(pdir);
1504+
#ifndef EMSCRIPTEN
1505+
/*
1506+
* Verify that there's a readable directory there; otherwise the Postgres
1507+
* installation is incomplete or corrupt. (A typical cause of this
1508+
* failure is that the postgres executable has been moved or hardlinked to
1509+
* some directory that's not a sibling of the installation lib/
1510+
* directory.)
1511+
*/
1512+
pdir = AllocateDir(pkglib_path);
1513+
if (pdir == NULL)
1514+
ereport(ERROR,
1515+
(errcode_for_file_access(),
1516+
errmsg("could not open directory \"%s\": %m",
1517+
pkglib_path),
1518+
errhint("This may indicate an incomplete PostgreSQL installation, or that the file \"%s\" has been moved away from its proper location.",
1519+
my_exec_path)));
1520+
FreeDir(pdir);
1521+
#endif
15201522

15211523
/*
15221524
* XXX is it worth similarly checking the share/ directory? If the lib/

src/backend/storage/smgr/md.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,6 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
746746
errhint("Check free disk space.")));
747747
}
748748

749-
// printf("! writing block %u in file \"%s\"\n",
750-
// blocknum, FilePathName(v->mdfd_vfd));
751-
752749
if (!skipFsync && !SmgrIsTemp(reln))
753750
register_dirty_segment(reln, forknum, v);
754751
}

src/backend/tcop/dest.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ static const DestReceiver debugtupDR = {
7777
DestDebug
7878
};
7979

80-
static const DestReceiver debugtup_jsonDR = {
81-
debugtup_json, debugtup_json_startup, debugtup_json_shutdown, donothingCleanup,
82-
DestDebugJson
83-
};
84-
8580
static const DestReceiver printsimpleDR = {
8681
printsimple, printsimple_startup, donothingCleanup, donothingCleanup,
8782
DestRemoteSimple
@@ -137,9 +132,6 @@ CreateDestReceiver(CommandDest dest)
137132
case DestDebug:
138133
return unconstify(DestReceiver *, &debugtupDR);
139134

140-
case DestDebugJson:
141-
return unconstify(DestReceiver *, &debugtup_jsonDR);
142-
143135
case DestSPI:
144136
return unconstify(DestReceiver *, &spi_printtupDR);
145137

@@ -208,7 +200,6 @@ EndCommand(const QueryCompletion *qc, CommandDest dest, bool force_undecorated_o
208200

209201
case DestNone:
210202
case DestDebug:
211-
case DestDebugJson:
212203
case DestSPI:
213204
case DestTuplestore:
214205
case DestIntoRel:
@@ -254,7 +245,6 @@ NullCommand(CommandDest dest)
254245

255246
case DestNone:
256247
case DestDebug:
257-
case DestDebugJson:
258248
case DestSPI:
259249
case DestTuplestore:
260250
case DestIntoRel:
@@ -298,7 +288,6 @@ ReadyForQuery(CommandDest dest)
298288

299289
case DestNone:
300290
case DestDebug:
301-
case DestDebugJson:
302291
case DestSPI:
303292
case DestTuplestore:
304293
case DestIntoRel:

src/backend/tcop/postgres.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
const char *debug_query_string; /* client-supplied query string */
9494

9595
/* Note: whereToSendOutput is initialized for the bootstrap/standalone case */
96-
CommandDest whereToSendOutput = DestRemote;
96+
CommandDest whereToSendOutput = DestDebug;
9797

9898
/* flag for logging end of session */
9999
bool Log_disconnections = false;
@@ -315,8 +315,6 @@ InteractiveBackend(StringInfo inBuf)
315315
* Even though we are not reading from a "client" process, we still want to
316316
* respond to signals, particularly SIGTERM/SIGQUIT.
317317
*/
318-
// FILE *query_in = NULL;
319-
320318
static int
321319
interactive_getc(void)
322320
{
@@ -330,11 +328,6 @@ interactive_getc(void)
330328
*/
331329
CHECK_FOR_INTERRUPTS();
332330

333-
// if (!query_in) {
334-
// printf("Reading query now\n");
335-
// query_in = fopen("/Users/stas/datadir/q.sql","r");
336-
// }
337-
338331
c = getc(stdin);
339332

340333
ProcessClientReadInterrupt(false);
@@ -529,9 +522,11 @@ ReadCommand(StringInfo inBuf)
529522
int result;
530523

531524
if (whereToSendOutput == DestRemote)
525+
#ifdef EMSCRIPTEN
532526
result = EmscriptenBackend(inBuf);
533-
else if (whereToSendOutput == DestDebugJson)
534-
result = EmscriptenBackend(inBuf);
527+
#else
528+
result = SocketBackend(inBuf);
529+
#endif
535530
else
536531
result = InteractiveBackend(inBuf);
537532
return result;
@@ -3749,6 +3744,10 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx,
37493744
{
37503745
argv++;
37513746
argc--;
3747+
#ifdef EMSCRIPTEN
3748+
/* We want to send output to the client using the wire protocol */
3749+
whereToSendOutput = DestRemote;
3750+
#endif
37523751
}
37533752
}
37543753
else

src/backend/utils/adt/json.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ static void json_categorize_type(Oid typoid,
6565
static void datum_to_json(Datum val, bool is_null, StringInfo result,
6666
JsonTypeCategory tcategory, Oid outfuncoid,
6767
bool key_scalar);
68+
static void add_json(Datum val, bool is_null, StringInfo result,
69+
Oid val_type, bool key_scalar);
6870
static text *catenate_stringinfo_string(StringInfo buffer, const char *addon);
6971

7072
/*
@@ -630,7 +632,7 @@ composite_to_json(Datum composite, StringInfo result, bool use_line_feeds)
630632
* printed many times, avoid using this; better to do the json_categorize_type
631633
* lookups only once.
632634
*/
633-
void
635+
static void
634636
add_json(Datum val, bool is_null, StringInfo result,
635637
Oid val_type, bool key_scalar)
636638
{

0 commit comments

Comments
 (0)