<?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: Kei</title>
    <description>The latest articles on DEV Community by Kei (@keiwitha).</description>
    <link>https://dev.to/keiwitha</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%2F914134%2F0e3bbfdb-d927-4c48-8f15-cfa04fedd491.png</url>
      <title>DEV Community: Kei</title>
      <link>https://dev.to/keiwitha</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/keiwitha"/>
    <language>en</language>
    <item>
      <title>I hate making resumes so much that I made a resume builder, and it was a blast.</title>
      <dc:creator>Kei</dc:creator>
      <pubDate>Tue, 03 Jan 2023 06:22:59 +0000</pubDate>
      <link>https://dev.to/keiwitha/i-hate-making-resumes-so-much-that-i-made-a-resume-builder-and-it-was-a-blast-2hc8</link>
      <guid>https://dev.to/keiwitha/i-hate-making-resumes-so-much-that-i-made-a-resume-builder-and-it-was-a-blast-2hc8</guid>
      <description>&lt;p&gt;Hello everyone, this is Kei.&lt;/p&gt;

&lt;p&gt;How do you make your resume when you are looking for a new job?&lt;/p&gt;

&lt;p&gt;I think it's important to have a good resume design, so every time I change jobs, I have to redesign my resume, but it's a lot of work.&lt;/p&gt;

&lt;p&gt;There are services that can create resumes for you, but it's hard to find a service that is suitable for me because, design-wise, they are either not suitable for the culture of the country or too classic.&lt;/p&gt;

&lt;p&gt;Even if you want to modify an existing template a little, you have to learn how the template works from scratch, which is not easy.&lt;/p&gt;

&lt;p&gt;So, I thought it would be nice if I could use a template that is super simple to manage resumes and easily customizable, and since I had some free time during New Year's, I made one myself from scratch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://resume-builder-k.netlify.app/" rel="noopener noreferrer"&gt;This&lt;/a&gt; is what I made.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fimq3ag3eu8i1dagxijxg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fimq3ag3eu8i1dagxijxg.gif" alt="Preview" width="400" height="266"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  About Features
&lt;/h2&gt;

&lt;p&gt;The functions available are all basic: creating the basic information needed for a resume. Saving. Loading.&lt;/p&gt;

&lt;p&gt;One of the unique features is that as long as you load a theme that is compatible with resume builder by URL, you can use that theme immediately.&lt;/p&gt;

&lt;p&gt;Each theme can use its own attribute values, and if the values corresponding to the theme are set in the custom attributes, the values will be automatically applied when the theme is changed.&lt;/p&gt;

&lt;p&gt;The information entered in the biography can be saved, so there is no need to enter custom attributes for each theme again as long as the data is loaded from the next time onward.&lt;/p&gt;

&lt;p&gt;Incidentally, the background data is saved in JSON format, so it will be more convenient if you save it in github or other file system.&lt;/p&gt;

&lt;h2&gt;
  
  
  About Themes
&lt;/h2&gt;

&lt;p&gt;Themes can be applied by entering a URL in the input form or selecting one from the dropdown.&lt;/p&gt;

&lt;p&gt;Currently, only one theme is available since this application itself was created during the New Year's holiday, but the &lt;a href="https://github.com/tonton-k37/resume-builder-themes" rel="noopener noreferrer"&gt;theme repository&lt;/a&gt; is open to the public, so we would be happy if anyone who thinks he/she is the one to create a theme would open it to the public.&lt;/p&gt;

&lt;p&gt;I am also planning to create a theme when I can take the time.&lt;/p&gt;

&lt;p&gt;Have a great job search, everyone!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>react</category>
      <category>openai</category>
    </item>
    <item>
      <title>My own mistakes that I should have done at that time</title>
      <dc:creator>Kei</dc:creator>
      <pubDate>Mon, 12 Dec 2022 09:03:03 +0000</pubDate>
      <link>https://dev.to/keiwitha/my-own-mistakes-that-i-should-have-done-at-that-time-55oi</link>
      <guid>https://dev.to/keiwitha/my-own-mistakes-that-i-should-have-done-at-that-time-55oi</guid>
      <description>&lt;p&gt;First of all, this article is a completely reflective post that focuses on my past mistakes, just talking about what I might have done differently. Some readers may know better ways to do this, etc. However, this is only based on my experience, so I would appreciate it if you could keep it warm.&lt;/p&gt;

&lt;h2&gt;
  
  
  If you get thrown a project one day, be prepared.
&lt;/h2&gt;

&lt;p&gt;That may not be the best way to put it. But when a project is thrown at you one day, it is usually because the project is not going well. If it is a simple staffing increase, it may not be. But if you look around and see that your predecessor is missing, the odds of going to hell are high. In such a situation, I would say to run anyway. If you can't escape, you might as well go buy a sleeping bag for the season. A sleeping bag is the safest way to sleep on an office chair.&lt;/p&gt;

&lt;h2&gt;
  
  
  Be the first to check for test codes
&lt;/h2&gt;

&lt;p&gt;When you take over a project, the major difference between you and your predecessor or your team is not coding skills, but domain knowledge. Clients tend to lump us all together as engineers, so they don't take into account the difference in domain knowledge that your predecessors have accumulated since the early days of development and their understanding of the current code. Therefore, they make demands based on the same assumptions as before, such as development time.&lt;/p&gt;

&lt;p&gt;The test code is to fill in these differences in experience as much as possible. Therefore, when you take over a project, the test code should be the first thing you look for. If you cannot find the test code, you should refrain from changing the code. Then, after passionately talking about the dangers of the current situation, tell them that they should prioritize writing tests first or refactoring now. Because we can't guarantee that it will work, and there is a possibility that another function will break without our knowledge. Besides, by writing tests and refactoring, it is often possible to get a sense of how the code was intended to be implemented. If you skip this step and proceed with development, and a bug occurs, it is not your predecessor or your customer who takes responsibility. In the end, it is you. Wouldn't you like to go home every day?&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't hate the code. If you hate it, rethink how your project is progressing
&lt;/h2&gt;

&lt;p&gt;The most common cause of project flame-outs is often an overloaded project progressing faster than they think it should. Especially in agile development, for example, there are too many feature requests from the customer, and the requests are carried to the engineers without being discarded. That is natural. If the development time is fixed, the customer wants as many functions implemented as possible. I would probably do the same.&lt;/p&gt;

&lt;p&gt;However, just like a conveyor belt in motion, if the speed is not properly adjusted, the amount of work per iteration will increase many times over, and eventually, we will choke ourselves. Let's act now to slow down the conveyor belt.&lt;/p&gt;

&lt;h2&gt;
  
  
  Customers don't know what's in the code
&lt;/h2&gt;

&lt;p&gt;Customers only know what they experience firsthand, such as whether the software is working properly. In other words, they have no other criteria to evaluate software. However, it is not always the case that the part of the software that you are in charge of is the easiest to evaluate. This is especially true when you are working on the back end or on a large function. In other cases, what looks surprisingly simple from the client's point of view may actually be based on an unbelievably complex process. No matter how hard you try to explain the difficulty of the process to the customer, they will never be able to empathize with it. This is not surprising because they are not engineers. If you are ever told by a client or your boss that you are unappreciative, calm down and smile back, because there are people in the world who feel the same way as you do. At least I am on your side.&lt;/p&gt;

&lt;h2&gt;
  
  
  To achieve functionality, you need to broaden your vision.
&lt;/h2&gt;

&lt;p&gt;With legacy code, you don't know what's going on in the first place, so trying to add a new feature often doesn't work the way you want it to. In fact, you may think it would be faster to start from scratch. But reality is merciless and will not allow us to do so. Perhaps, though, if we wait 20 years, it might be possible.&lt;/p&gt;

&lt;p&gt;In such a case, let's just try to find out if there really is another way to realize the request. It is okay to take the plunge once and move the data out of the current application and let another tool handle the process. There must be other ways to achieve the objective.&lt;/p&gt;

&lt;p&gt;And always keep the following thoughts in the back of your mind." The engineer's job is to provide the methods and things to solve a problem. And we should not determine for ourselves the extent to which we look for solutions. Because we are so desperate that we only see what is in front of us."&lt;/p&gt;

&lt;h2&gt;
  
  
  Are you sure you got that estimate right?
&lt;/h2&gt;

&lt;p&gt;When you are asked to estimate a feature, are you sure you are getting the correct estimate? Remember that software development estimates are based on the uncertainty of the system. If you think you can do it in 10 days in your estimate, you should actually estimate 14 days or around. The reason for this is that in many cases, the actual work is different from what they imagined after they actually started working on it. When asked, "Will it really take that long?" They will be convinced if you tell them that there are many uncertainties and that you want to give them plenty of time to work on it. Besides, they will not blame you if the work is completed earlier than you imagined, so there is no disadvantage in estimating more than enough time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't let them throw away the business logic
&lt;/h2&gt;

&lt;p&gt;It is a common practice in contracted development to have the business logic for a service developed by the client thrown to the engineers. This is not so common in cases where the company is conscious of digitalization, such as when the methods it has cultivated in-house are incorporated into software. On the other hand, it is very common in cases where the client wants to create a new service. In such cases, even the clients themselves do not have a clear idea of what they actually need to do and how to put it together to create what they want to create. And the engineers are forced to think about the process. And in the worst case scenario, the product is not at all what they had in mind.&lt;/p&gt;

&lt;p&gt;Furthermore, not knowing the logic of their business is like driving a car without a driver's license. It would be unwilling for a developer to proceed with development knowing that the worst possible future awaits them. So, let's help our clients to think about the logic together with us. There is no need to use complicated terminology. You can use a ubiquitous language that is a common language between the customer and the engineer. Anyway, help the customer to understand how the software system works and to think about the logic on their own.&lt;/p&gt;

</description>
      <category>productivity</category>
    </item>
    <item>
      <title>How to improve your Database performance</title>
      <dc:creator>Kei</dc:creator>
      <pubDate>Mon, 12 Dec 2022 06:09:42 +0000</pubDate>
      <link>https://dev.to/keiwitha/how-to-improve-your-database-performance-a9m</link>
      <guid>https://dev.to/keiwitha/how-to-improve-your-database-performance-a9m</guid>
      <description>&lt;p&gt;Hello everyone, I am Kei and I'm here to talk about database optimization in PostgreSQL&lt;/p&gt;

&lt;p&gt;One question before We start.&lt;/p&gt;

&lt;p&gt;How do you store data when developing applications these days?&lt;/p&gt;

&lt;p&gt;Recently, many small application developers are using so-called NoSQL, such as Firestore.&lt;/p&gt;

&lt;p&gt;I myself use Firestore as my main data store for both work and pleasure, so I have recently moved away from the strong SQL and PostgreSQL RDBs that I am familiar with from the past.&lt;/p&gt;

&lt;p&gt;But I'm starting to think lately that this is not a very good thing.&lt;/p&gt;

&lt;p&gt;Naturally, NoSQL is convenient at first glance because of its fast implementation and transaction speed, but after using it for a long time, you start to realize that the running cost of NoSQL is surprisingly high.&lt;/p&gt;

&lt;p&gt;Especially when handling core business data, it is difficult to ensure the relevance of data, and you have to be even more careful. Therefore, I believe that NoSQL cannot be a perfect substitute for RDB, and that it is important to use it where it is essential. There is no silver bullet.&lt;/p&gt;

&lt;p&gt;So, recently I've been switching where to store data from Firestore to PostgreSQL for some of my projects, but it's been a few years since I've used it and I've forgotten a lot of things, so I wanted to relearn some things.&lt;/p&gt;

&lt;p&gt;So, I'm going to share some SQL How To's with a focus on improving database performance over the next few posts. (By the way, I will be using PostgreSQL.&lt;/p&gt;

&lt;h2&gt;
  
  
  Flow of Query
&lt;/h2&gt;

&lt;p&gt;Now, since this is the first article in this series, let's start with what we are most likely to work on when performing database performance: query optimization.&lt;/p&gt;

&lt;p&gt;To do this, the most important thing is to understand how DMBS receives and evaluates queries.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kTTp0SYK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pp74u8m5klgthc3zv3vf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kTTp0SYK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pp74u8m5klgthc3zv3vf.png" alt="Image description" width="880" height="619"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Raghu Ramakrishnan, Johannes Gehrke, Database Management System 3rd ed, McGraw-Hill, 2002, p.405&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The figure above simulates the query processing flow.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Parser&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The role of the parser is to parse SQL statements. The parser parses the SQL statements that we normally write and execute, and checks them for syntax errors. After parsing is complete, the parser also converts the SQL to a format that can be processed by a DBMS.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Optimizer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Optimizer, as the name implies, creates the best way to access the data, and it selects the least expensive execution plan based on various conditions such as the presence or absence of Indexes, the degree of data distribution, and information on the internal parameters of the DBMS itself.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Catalog Manager&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The information needed to develop an execution plan in Optimizer is done through the Catalog Manager. The Catalog Manager stores statistical information about the tables, for example, the number of records.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Plan Evaluation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After the Optimizer has generated the execution plans from the SQL statements, it is responsible for selecting the best plan from these execution plans. Unfortunately, the plan selected by Plan Evaluation is not always the best.&lt;/p&gt;

&lt;p&gt;Now that you have come this far, I am sure that you somehow understand the importance of the Optimizer function in improving the performance of the database.&lt;/p&gt;

&lt;p&gt;But whatever the case may be, let's write and execute some SQL at hand to see how the whole process works!&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;create&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;serial&lt;/span&gt; &lt;span class="k"&gt;primary&lt;/span&gt; &lt;span class="k"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;user_name&lt;/span&gt; &lt;span class="nb"&gt;varchar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;not&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="err"&gt;$$&lt;/span&gt;
&lt;span class="k"&gt;begin&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="n"&gt;loop&lt;/span&gt;
&lt;span class="k"&gt;insert&lt;/span&gt; &lt;span class="k"&gt;into&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s1"&gt;'user'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt; &lt;span class="n"&gt;loop&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;$$&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;explain&lt;/span&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;users&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'5000user'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First, without thinking, create a user table and then create records for 1000 users.&lt;/p&gt;

&lt;p&gt;Now let's add the word explore to the SQL statement and run it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Fll41Uuk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w69uj0z78awdxat7uomq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Fll41Uuk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w69uj0z78awdxat7uomq.png" alt="Image description" width="708" height="144"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Interestingly, the information was different from what we normally see on our screens. Yes, this is the execution plan itself, which shows how the query is being executed, and this is how we, as engineers, can make sure that the execution plan is properly formulated.&lt;/p&gt;

&lt;p&gt;Here is how we see this information&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Seq Scan&lt;/p&gt;

&lt;p&gt;This represents the type of operation, which can vary depending on the situation. Also note that the notation varies depending on the type of DBMS. In this case, since we are using PostgreSQL, this Seq Scan indicates that a full scan is being performed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;users&lt;/p&gt;

&lt;p&gt;This is the name of the operation target. In this case, we are operating on the users table, so it is denoted as users.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In parentheses&lt;/p&gt;

&lt;p&gt;Information about the operation target is displayed here. The cost and number of rows to retrieve, and width is the average size of the rows to be retrieved.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those with good senses may have already noticed here that this time, user_name is set sequentially numbered, so rows=1 should not be the case. But this is no mystery; the plan itself is created in an optimal way. However, as I explained earlier, the execution plan is created based on information from the catalog manager, so the current situation is that the information from the catalog manager is incorrect, i.e., the execution plan is created based on the wrong information.&lt;/p&gt;

&lt;p&gt;Although we said that the catalog manager creates statistics based on the information in the tables, the fact is that statistics are not updated immediately after data is stored in the database. (It is usually done automatically on a regular basis.&lt;/p&gt;

&lt;p&gt;(Usually, it is done automatically on a regular basis.) Also, if the amount of data is small, it does not have a significant impact on performance even if the statistics update is not done immediately. However, if you have a large amount of data at one time, as in this case, or if you want to measure performance properly after the statistics are updated, the current state is not appropriate.&lt;/p&gt;

&lt;p&gt;So I have to wait until the next update? When? Don't worry! Don't worry! postgreSQL has SQL to update the statistics.&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;analyze&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is all it takes to update the statistics in the users table. Try executing the same SQL statement as before and check the information.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nyZZ65gF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hwv6ekd1keg4eqb0tizl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nyZZ65gF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hwv6ekd1keg4eqb0tizl.png" alt="Image description" width="710" height="140"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we expected, you see that rows is displayed as 1, which is the correct number of rows. However, it is important to note that the statistics are only a guide and do not necessarily show the correct number of rows. Especially for a simple query like this one, I am sure it is correct, but the more complex the query is, the more suspicious it becomes, so always keep this in mind.&lt;/p&gt;

&lt;p&gt;Let's play a little more interestingly.&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;create&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;item_id&lt;/span&gt; &lt;span class="nb"&gt;integer&lt;/span&gt; &lt;span class="k"&gt;not&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;item_name&lt;/span&gt; &lt;span class="nb"&gt;varchar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; 

&lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="err"&gt;$$&lt;/span&gt;
&lt;span class="k"&gt;begin&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;100000&lt;/span&gt; &lt;span class="n"&gt;loop&lt;/span&gt;
&lt;span class="k"&gt;insert&lt;/span&gt; &lt;span class="k"&gt;into&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="k"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="s1"&gt;'user'&lt;/span&gt; &lt;span class="p"&gt;));&lt;/span&gt; 
&lt;span class="k"&gt;end&lt;/span&gt; &lt;span class="n"&gt;loop&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;$$&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;analyze&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;drop&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;create&lt;/span&gt; &lt;span class="k"&gt;index&lt;/span&gt; &lt;span class="n"&gt;item_name_idx&lt;/span&gt; &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item_name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;explain&lt;/span&gt;
&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;item_name&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;
&lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;item_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'50000user'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7Yp15cBZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pf19weh0qtwlxyo9idq0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Yp15cBZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pf19weh0qtwlxyo9idq0.png" alt="Image description" width="724" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember this value! Next, let's put something called index against user_name in the users table.&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;create&lt;/span&gt; &lt;span class="k"&gt;index&lt;/span&gt; &lt;span class="n"&gt;user_name_idx&lt;/span&gt; &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rsCY46bl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2vhvmwdp684gyhqvpmxj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rsCY46bl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2vhvmwdp684gyhqvpmxj.png" alt="Image description" width="880" height="128"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The results have changed from Seq Scan to Index Scan.&lt;/p&gt;

&lt;p&gt;Now, here is a question for you: Have you ever heard of B-Tree?&lt;/p&gt;

&lt;p&gt;(I'll spare you the details of B-Tree, as you can find plenty of information about it on the Internet.)&lt;/p&gt;

&lt;p&gt;PostgresSQL also uses B-Tree, so it would be faster to put an index on user_name of items like this.&lt;/p&gt;

&lt;p&gt;It should be faster to retrieve the data. However, when we look at the actual values, we see that the cost is lower before pasting the index.&lt;/p&gt;

&lt;p&gt;Actually, this is because postgreSQL's EXPLAIN does not actually issue SQL, but returns an estimate of the execution plan. Therefore, if the values are off by a large amount, as in this case, you can get the correct information by specifying that you can actually execute the query.&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;drop&lt;/span&gt; &lt;span class="k"&gt;index&lt;/span&gt; &lt;span class="n"&gt;item_name_idx&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;explain&lt;/span&gt; &lt;span class="k"&gt;analyze&lt;/span&gt;
&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;item_name&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;
&lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;item_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'50000user'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mGxzfNwg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mwddxub19i3th61qsk8i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mGxzfNwg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mwddxub19i3th61qsk8i.png" alt="Image description" width="880" height="191"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's add an index.&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;create&lt;/span&gt; &lt;span class="k"&gt;index&lt;/span&gt; &lt;span class="n"&gt;item_name_idx&lt;/span&gt; &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item_name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;explain&lt;/span&gt; &lt;span class="k"&gt;analyze&lt;/span&gt;
&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;item_name&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;
&lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;item_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'50000user'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7wwnvgpb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jj5v54jrms9ipm87t2y7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7wwnvgpb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jj5v54jrms9ipm87t2y7.png" alt="Image description" width="880" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With explain analyze, we can now see the correct execution time and it is clear that the index is effective.&lt;/p&gt;

&lt;p&gt;Now that we know how to read the execution plan, let's try a more complex query.&lt;/p&gt;

&lt;p&gt;What we will do here is split the categories into 1 and 2 according to the birth year of the monsters in the Pokémon table (the release date of each Pokémon).&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;create&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="n"&gt;monsters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;serial&lt;/span&gt; &lt;span class="k"&gt;primary&lt;/span&gt; &lt;span class="k"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;monster_name&lt;/span&gt; &lt;span class="nb"&gt;varchar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nb"&gt;year&lt;/span&gt; &lt;span class="nb"&gt;integer&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;insert&lt;/span&gt; &lt;span class="k"&gt;into&lt;/span&gt; &lt;span class="n"&gt;monsters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;monster_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Picachu'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1996&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;insert&lt;/span&gt; &lt;span class="k"&gt;into&lt;/span&gt; &lt;span class="n"&gt;monsters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;monster_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Chikorita'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1999&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;insert&lt;/span&gt; &lt;span class="k"&gt;into&lt;/span&gt; &lt;span class="n"&gt;monsters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;monster_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Torchic'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2002&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;insert&lt;/span&gt; &lt;span class="k"&gt;into&lt;/span&gt; &lt;span class="n"&gt;monsters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;monster_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Piplup'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2006&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;insert&lt;/span&gt; &lt;span class="k"&gt;into&lt;/span&gt; &lt;span class="n"&gt;monsters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;monster_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Oshawott'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2010&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;insert&lt;/span&gt; &lt;span class="k"&gt;into&lt;/span&gt; &lt;span class="n"&gt;monsters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;monster_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Fennekin'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2013&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;insert&lt;/span&gt; &lt;span class="k"&gt;into&lt;/span&gt; &lt;span class="n"&gt;monsters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;monster_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Rowlet'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2016&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;insert&lt;/span&gt; &lt;span class="k"&gt;into&lt;/span&gt; &lt;span class="n"&gt;monsters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;monster_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Scorbunny'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2019&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, let's write an SQL statement that gets exactly the same result in the two different method pictures.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hAAk23T1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qiofey5o7sxfib5ow6hi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hAAk23T1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qiofey5o7sxfib5ow6hi.png" alt="Image description" width="522" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;case1&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;explain&lt;/span&gt;
&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;monster_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'1'&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;category&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;monsters&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;
&lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;year&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;2006&lt;/span&gt;
&lt;span class="k"&gt;union&lt;/span&gt;
&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;monster_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'2'&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;category&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;monsters&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;
&lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;year&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2006&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wbHPXVSZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nw6893h6zb2oevdqzzyz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wbHPXVSZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nw6893h6zb2oevdqzzyz.png" alt="Image description" width="880" height="310"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;case2&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;explain&lt;/span&gt;
&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;monster_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="nb"&gt;year&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;2006&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
&lt;span class="s1"&gt;'1'&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt;
&lt;span class="s1"&gt;'2'&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;category&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;monsters&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kfDxYwXF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5a72u72dbywwujidcdv7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kfDxYwXF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5a72u72dbywwujidcdv7.png" alt="Image description" width="880" height="110"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's run the queries for case1 and case2. To our surprise, we found that the results of the execution plan are very different between case1 and case2.&lt;/p&gt;

&lt;p&gt;Why does this happen?&lt;/p&gt;

&lt;p&gt;The reason is obvious: when we are doing union, we are using the select clause twice to combine the results of each. On the other hand, with the case method, the select clause is issued only once, resulting in fewer scans and lower execution costs.&lt;/p&gt;

&lt;p&gt;So, what do you think? We have focused on the optimizer, but this is just a brief example, and we are only at the beginning of some very interesting database performance tuning.&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

</description>
      <category>database</category>
      <category>tutorial</category>
      <category>performance</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
