<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: GhostVaibhav</title>
    <description>The latest articles on DEV Community by GhostVaibhav (@ghostvaibhav).</description>
    <link>https://dev.to/ghostvaibhav</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F528283%2F6dd0e242-709d-4874-8e9d-bb65c77f5ae0.jpeg</url>
      <title>DEV Community: GhostVaibhav</title>
      <link>https://dev.to/ghostvaibhav</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ghostvaibhav"/>
    <language>en</language>
    <item>
      <title>But, what is a graph database?</title>
      <dc:creator>GhostVaibhav</dc:creator>
      <pubDate>Tue, 26 Sep 2023 17:59:58 +0000</pubDate>
      <link>https://dev.to/ghostvaibhav/but-what-is-a-graph-database-3je</link>
      <guid>https://dev.to/ghostvaibhav/but-what-is-a-graph-database-3je</guid>
      <description>&lt;p&gt;Umm..., as the name suggests a graph database consists of a graph. Obviously! However, the actual data is stored in the vertices and their relationships are represented as edges. That is what forms the graph. This graph could be previewed in many databases including AgensGraph. Getting this graph preview for a database storing millions of vertices and billions of edges may not mean anything, as you mentally can't think about the scale of that data. While you can't, computers can! So, in this article, I will be discussing some advantages of these graph databases and their use cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Schema-less
&lt;/h2&gt;

&lt;p&gt;As the title itself suggests, a graph database doesn't have a fixed schema. Since the graph databases store data as objects instead of inserting them into tables, the capacity is increased and various formats are accepted.&lt;/p&gt;

&lt;p&gt;A large amount of data can be stored. Also, the data element can be both independent and dependent, allowing for better operability. With this, the graph databases are quite flexible in their design. For example, consider adding a new column to an existing table, you would need to know the underlying structure of the database, the foreign key, any constraints, views, etc. With graph databases, inserting a vertex is as simple as it can get. You can also easily connect as well as disconnect it from any number of vertices. Furthermore, these vertices can have single or multiple labels associated with them for even more granular control.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Query Processing Speed
&lt;/h2&gt;

&lt;p&gt;The conventional databases need to execute a join for displaying relationships between any two tables. This is a very costly operation. Also, if we have to have more depth to it, like, we have to multiple join operations, the complexity would just multiply.&lt;/p&gt;

&lt;p&gt;This is where the graph databases take over the conventional databases. Finding the relationships in a graph database is much simpler and faster in comparison since they are purpose-built for this kind of use case. The difference becomes more pronounced when executing deep-level joins.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Intuitive Modeling
&lt;/h2&gt;

&lt;p&gt;The heading itself describes the whole problem. When we take a real-life problem, we have to model it in a whole new way just to fix it through conventional database systems. While this is doable, when the use cases increase, the complexity rises steeply. Graph databases excel in this field as well. Whatever the real-world problem may be, you will always be able to convert it into a graph database and represent it through a set of vertices and edges.&lt;/p&gt;

&lt;p&gt;On an ending note, I would like to clarify that, graph databases are built for specific use cases. If your use case lies close to those, consider switching over to them, else, you can always fall back to the industry standard conventional databases.&lt;/p&gt;

&lt;p&gt;This was all for the article. Until then, see ya!&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>sql</category>
      <category>apacheage</category>
    </item>
    <item>
      <title>From console to rows - the processing of a query in Postgres</title>
      <dc:creator>GhostVaibhav</dc:creator>
      <pubDate>Mon, 25 Sep 2023 15:52:37 +0000</pubDate>
      <link>https://dev.to/ghostvaibhav/from-console-to-rows-the-processing-of-a-query-in-postgres-1if5</link>
      <guid>https://dev.to/ghostvaibhav/from-console-to-rows-the-processing-of-a-query-in-postgres-1if5</guid>
      <description>&lt;p&gt;The journey of a query is quite exciting and complicated. As always, this will be a beginner-friendly post so everyone can follow. I would also attach some material that you can look after for an even more in-depth understanding of the topic.&lt;/p&gt;

&lt;p&gt;Whenever you type a query in the console, it goes through the following steps for execution - &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Parser&lt;/li&gt;
&lt;li&gt;Analyzer&lt;/li&gt;
&lt;li&gt;Rewriter&lt;/li&gt;
&lt;li&gt;Planner&lt;/li&gt;
&lt;li&gt;Executor&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We will be looking at these from a high level.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Parser
&lt;/h2&gt;

&lt;p&gt;For any language, the parser has only one functionality and that is to parse the tokens (or generate some meaning from the statements). That is exactly what the parser does in Postgres as well. It creates a parse tree from the query.&lt;/p&gt;

&lt;p&gt;You might ask, what is a parse tree? Well, it is just a tree that contains several fields of a base statement. That base statement could be anything like SELECT, UPDATE, ALTER, etc. Let's take the SELECT statement as an example. For a SELECT statement, you have to specify a table in the FROM clause. This is stored in a list named &lt;code&gt;List *fromClause&lt;/code&gt;. Similarly, other parameters are stored respectively.&lt;/p&gt;

&lt;p&gt;A very important note to mention here is that the parser only checks for any syntactical mistakes and not semantic mistakes. Let's take an example.&lt;/p&gt;

&lt;p&gt;Consider there is a table named &lt;code&gt;students&lt;/code&gt;. Then, the following query would return an error in parsing stage -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;students&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But, the following query won't -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;studentsz&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All the semantic checking happens in the Analyzer stage.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Analyzer
&lt;/h2&gt;

&lt;p&gt;The main purpose of the analyzer is to semantically check the parse tree and generate the query tree. This structure also contains the metadata regarding the query. Each leaf forms a list or a tree that specifies the other values in that particular clause. It converts the tree from kind of a statement tree to a query tree. That's pretty much what it does. Let's move on to the next one.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Rewriter
&lt;/h2&gt;

&lt;p&gt;Rewriter as the name suggests rewrites the query tree according to the rules defined in the &lt;code&gt;pg_rules&lt;/code&gt; system catalog. This mechanism is complicated as well as interesting. So, if you want to further read, I will give some links at the end. &lt;code&gt;VIEWS&lt;/code&gt; are generated and checked through the rewriter system.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Planner and Executor
&lt;/h2&gt;

&lt;p&gt;The planner makes a query plan tree from the query tree and the executor executes it. The planner is a very complicated system on its own. It uses cost-based optimization for generating the query plan tree. Also, no planner hints are supported in Postgres. Again, this is a very vast topic that can be explored deeply. For a beginner, only the former information is sufficient to know how a query is executed.&lt;/p&gt;

&lt;p&gt;In the end, I would like to add that these subsystems are no different than compilers. All of the processes that are performed in a compiler are also performed here.&lt;/p&gt;

&lt;p&gt;For further reading, I have attached the materials below - &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.interdb.jp/pg/pgsql03.html"&gt;https://www.interdb.jp/pg/pgsql03.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://etutorials.org/SQL/Postgresql/Part+I+General+PostgreSQL+Use/Chapter+4.+Performance/Understanding+How+PostgreSQL+Executes+a+Query/"&gt;https://etutorials.org/SQL/Postgresql/Part+I+General+PostgreSQL+Use/Chapter+4.+Performance/Understanding+How+PostgreSQL+Executes+a+Query/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=RNDTO33hVtY&amp;amp;ab_channel=EDB"&gt;https://www.youtube.com/watch?v=RNDTO33hVtY&amp;amp;ab_channel=EDB&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Thanks&lt;/em&gt; &lt;strong&gt;for&lt;/strong&gt; &lt;code&gt;reading&lt;/code&gt; and &lt;em&gt;until then&lt;/em&gt;, &lt;strong&gt;see ya&lt;/strong&gt;!&lt;/p&gt;

</description>
      <category>apacheage</category>
      <category>postgres</category>
      <category>sql</category>
    </item>
    <item>
      <title>Memory behind Postgres</title>
      <dc:creator>GhostVaibhav</dc:creator>
      <pubDate>Fri, 22 Sep 2023 04:18:17 +0000</pubDate>
      <link>https://dev.to/ghostvaibhav/memory-behind-postgres-3apk</link>
      <guid>https://dev.to/ghostvaibhav/memory-behind-postgres-3apk</guid>
      <description>&lt;p&gt;Without diving a lot into the intricacies of the underlying architecture of Postgres, we'll be looking at it from the top.&lt;/p&gt;

&lt;p&gt;Memory architecture in Postgres is classified into two broad categories: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Local Memory Area&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Shared Memory Area&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As the name suggests, the local memory area is used by backend processes for their use. While the shared memory area is shared between all the processes.&lt;/p&gt;

&lt;p&gt;Now, let's talk about the local memory area.&lt;/p&gt;

&lt;h2&gt;
  
  
  Local Memory Area
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Each backend process allocates a memory area for query processing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These areas are further divided where their sizes are either fixed or variable. Some areas are discussed below - &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Sub-Area&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;work_mem&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The executor uses this area for sorting tuples by &lt;code&gt;ORDER BY&lt;/code&gt; and &lt;code&gt;DISTINCT&lt;/code&gt; operations. It also uses it for joining tables by merge-join and hash-join operations.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;maintenance_work_mem&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;This parameter is used for some kinds of maintenance operations (&lt;code&gt;VACUUM&lt;/code&gt;, &lt;code&gt;REINDEX&lt;/code&gt;).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;temp_buffers&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The executor uses this area for storing temporary tables.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Shared Memory Area
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;A shared memory area is allocated by a PostgreSQL server when it starts up.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These areas are also further divided into various sub-sections that are further discussed below - &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Sub-Area&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Shared buffer pool&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;PostgreSQL loads pages within tables and indexes from persistent storage to a shared buffer pool, and then operates on them directly. In itself, this is a huge topic and can become very complicated if we delve into all the types and sizes of the buffers.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;WAL buffer&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;PostgreSQL supports the WAL (Write ahead log) mechanism to ensure that no data is lost after a server failure. WAL data is a transaction log in PostgreSQL and the WAL buffer is a buffering area of the WAL data before writing it to a persistent storage.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Commit log&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The commit log (CLOG) keeps the states of all transactions, and is part of the concurrency control mechanism. The commit log is allocated to the shared memory and used throughout transaction processing.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These are not the only areas where the memory is allocated, memory is allocated for the following as well - &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sub-areas for the various access control mechanisms&lt;/li&gt;
&lt;li&gt;Sub-areas for the various background processes&lt;/li&gt;
&lt;li&gt;Sub-areas for transaction processing, and others&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This post was just a beginner-friendly way to introduce to the readers about the memory architecture of the Postgres server. Also this, in no way is complete and the following could be referred to for further reading - &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=PM1rqdCavo0"&gt;https://www.youtube.com/watch?v=PM1rqdCavo0&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Until then, thank you for your time and see ya!&lt;/p&gt;

</description>
      <category>apacheage</category>
      <category>postgres</category>
      <category>sql</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
