This is an automated email from the ASF dual-hosted git repository.
joshinnis pushed a commit to branch developer-manual
in repository https://gitbox.apache.org/repos/asf/age-website.git
The following commit(s) were added to refs/heads/developer-manual by this push:
new e2dce1e fix some typos (#97)
e2dce1e is described below
commit e2dce1e4346c20a2c75ba9d90cdfe3cea8ca826a
Author: Arunesh Choudhary <[email protected]>
AuthorDate: Sun Oct 16 19:34:54 2022 -0400
fix some typos (#97)
---
docs/postgres/node.md | 91 ++++++++++++++++++++++++++-------------------------
1 file changed, 46 insertions(+), 45 deletions(-)
diff --git a/docs/postgres/node.md b/docs/postgres/node.md
index 281d6ab..53d8bde 100644
--- a/docs/postgres/node.md
+++ b/docs/postgres/node.md
@@ -4,7 +4,7 @@
Postgres has a default struct that it uses for throughout most of its query
processing engine, <a
href='https://github.com/postgres/postgres/blob/master/src/include/nodes/nodes.h#L105'>Node</a>.
The Node struct is defined as follows:
-```
+```c
typedef struct Node
{
NodeTag type;
@@ -15,54 +15,54 @@ The stuct Node and Postgres as a whole take advantage of
pointers and how C allo
<b>NOTE:</b> This is not a datatype that someone using Postgres needs to be
concerned about, only someone working with Postgres Internals. Postgres
datatypes and the Datum data type will be discussed later.
-## What is a Pointer?
-
+## What is a Pointer?
+
Unlike a variable a pointer stores the memory address of a variable. In other
words, it tells you where in memory something is located. Its a pretty simple
concept, that holds a lot of complexity and power within it.
For a full tutorial of pointers you can <a
href='https://www.youtube.com/watch?v=zuegQmMdy8M&ab_channel=freeCodeCamp.org'>watch
this tutorial.</a>
-For our purposes, the important thing to note about pointers is. All pointers
are the same: a 4 byte integer.
+For our purposes, the important thing to note about pointers is, all the
pointers are of same size: INT 4 byte.
You can denote pointers of different types such as:
-```
+```c
int *int_ptr;
char *string_ptr;
myStruct *struct_ptr;
void *void_ptr;
-```
-All of these pointers as far a the hardware and memory is concerned are the
same: they are 4 byte integer.
+```
+
+All of these pointers as far as the hardware and memory is concerned are of
the same size: INT 4 byte.
## What is a Struct?
-A struct is a composite data type that defines a physically group list of
variables in one name in a <b>continous</b> block of memory.
+A `struct` is a composite data type that defines a physically group list of
variables in one name in a <b>continous</b> block of memory.
If we have a struct defined as:
-```
-typedef struct myStruct
-{
+```c
+typedef struct myStruct
+{
int var1;
float var2;
- char var3;
-} myStruct;
-```
-
-When we allocate room for that struct, a set amount of bytes for the struct
will be found in memory and allocated. In our above example, on most modern
systems: 4 bytes for var1, 4 bytes for var2 and 1 byte for var3 resulting in 9
bytes total being allocated for the struct, and they will be allocated in the
order that they are defined above.
+ char var3;
+} myStruct;
+```
+When we allocate room for that struct, a set amount of bytes for the struct
will be found in memory and allocated. In our above example, on most modern
systems: **4 bytes for var1**, **4 bytes for var2** and **1 byte for var3**
resulting in `9 bytes` total being allocated for the struct, and they will be
allocated in the order that they are defined above.
-for a further tutorial of structs please review this <a
href='https://www.simplilearn.com/tutorials/c-tutorial/structure-in-c'>tutorial.</a>
+For a further tutorial on structs, please review this <a
href='https://www.simplilearn.com/tutorials/c-tutorial/structure-in-c'>tutorial.</a>
## Pointers to Structs
When you create a pointer to a struct, what is contained in the pointer is the
address of the first byte of the struct. When accessing an element in a struct
with a pointer, such as:
-```
-myStruct *str = malloc(sizeof(myStruct));
-str->var2 = 1.0;
-```
+```c
+myStruct *str = malloc(sizeof(myStruct));
+str->var2 = 1.0;
+```
-The address of the pointer is offset by the distance that var2 is from the
start of the struct. In this case, is adress of the pointer + 4 bytes, to
bypass the int field in the struct.
+The address of the pointer is offset by the distance that var2 is from the
start of the struct. In this case, is address of the pointer + 4 bytes, to
bypass the `int` field in the struct.
### Void Pointers and Pointer Casting
@@ -70,34 +70,35 @@ One of the more unique features that C offers is the void
pointer. This offers p
This pointer knows the address in memory that something is located, but it
doesn't know what is located there, so:
-
-```
+```c
void myFunction(void *ptr)
{
ptr->var1 = 1;
-}
-```
+}
+```
-Will throw an error. However, you can cast the void pointer to the pointer of
another type.
+The above code will throw an error. However, you can cast the void pointer to
the pointer of another type.
-```
-void myFunction(void *ptr)
{
+```c
+void myFunction(void *ptr){
myStruct *str = (myStruct *)ptr;
- str->var1 = 1;
-}
-```
+ str->var1 = 1;
+}
+```
+
+The code above will work.
-Will work. This opens opportunity for developers to create functions that are
more versitile that if the developer needs know exactly what something was
pointing to and code for all situations. However, developers need to be careful
with this feature because it allows for some very strange behavior if the
developer does not use them carefully.
+This opens opportunity for developers to create functions that are more
versitile that if the developer needs know exactly what something was pointing
to and code for all situations. However, developers need to be careful with
this feature because it allows for some very strange behavior if the developer
does not use them carefully.
Postgres has designed a way to use the power of void pointers, but with
certain precautions that make them safer to use.
-## How Postgres Uses Structs and Pointers
+## How Postgres Uses Structs and Pointers
Void pointers assume nothing about what the pointer is referencing. The Node
struct on the other hand know about one field the <a
href='https://github.com/postgres/postgres/blob/REL_11_17/src/include/nodes/nodes.h#L26'>enum
NodeType</a>. Nearly all the postgres data structures used in the query
processing engine start with this field.
-For example, here is the data structure that represents a fucntion call in the
parser phase:
+For example, here is the data structure that represents a function call in the
parser phase:
-```
+```c
typedef struct FuncCall
{
NodeTag type;
@@ -113,11 +114,11 @@ typedef struct FuncCall
CoercionForm funcformat; /* how to display this node */
int location; /* token location, or
-1 if unknown */
} FuncCall;
-```
+```
and here is the data structure that represents a constant in the parser phase.
-```
+```c
typedef struct A_Const
{
NodeTag type;
@@ -125,8 +126,7 @@ typedef struct A_Const
bool isnull; /* SQL NULL constant */
int location; /* token location, or
-1 if unknown */
} A_Const;
-```
-
+```
Given that each other these things a function can appear in a large
combination of ways:
@@ -136,9 +136,9 @@ SELECT 1, function_call();
SELECT function_call(), 1;
```
-Many parts of the code don't need to know the specifics, but since each start
with NodeTag, these functions can pass Node to each other and not have to care
about the details it isn't concerned with.
+Many parts of the code don't need to know the specifics, but since each start
with `NodeTag`, these functions can pass Node to each other and not have to
care about the details it isn't concerned with.
-For example the transformExpr function, which is what converts nodes such as
these from parser nodes to their analyze node couterparts:
+For example the `transformExpr` function, which is what converts nodes such as
these from parser nodes to their analyze node couterparts:
```
extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind
exprKind);
@@ -146,9 +146,9 @@ extern Node *transformExpr(ParseState *pstate, Node *expr,
ParseExprKind exprKin
Can be used in a generic way, reducing the number of permutations of a
function that needs to be created, when something is similar but not exact.
-The at points where the differences do matter, the NodeTag can be checked and
the correct logic can be run:
+At the points where the differences do matter, the `NodeTag` can be checked
and the correct logic can be run:
-```
+```c
switch (nodeTag(node))
{
case T_FuncCall:
@@ -157,7 +157,8 @@ The at points where the differences do matter, the NodeTag
can be checked and th
case T_A_Const:
result = (Node *) make_const(pstate, (A_Const *) node);
break;
-```
+ }
+```
## Extensible Nodes