<?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: Soha Mohamed</title>
    <description>The latest articles on DEV Community by Soha Mohamed (@soha_mohamed_ce989).</description>
    <link>https://dev.to/soha_mohamed_ce989</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%2F3316448%2F7a5f9e41-c2b7-433d-998a-9e7d49e52933.jpg</url>
      <title>DEV Community: Soha Mohamed</title>
      <link>https://dev.to/soha_mohamed_ce989</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/soha_mohamed_ce989"/>
    <language>en</language>
    <item>
      <title>Filtering Data Where It Matters: SQL vs Application Logic</title>
      <dc:creator>Soha Mohamed</dc:creator>
      <pubDate>Fri, 24 Apr 2026 17:02:24 +0000</pubDate>
      <link>https://dev.to/soha_mohamed_ce989/filtering-data-where-it-matters-sql-vs-application-logic-15mb</link>
      <guid>https://dev.to/soha_mohamed_ce989/filtering-data-where-it-matters-sql-vs-application-logic-15mb</guid>
      <description>&lt;p&gt;Hey,&lt;/p&gt;

&lt;p&gt;This article is completely written by me. I just asked ChatGPT to help me choose the key points, so forgive me if it’s not perfect.&lt;/p&gt;

&lt;p&gt;Today, I was trying to break the boredom of repeated studying, so I went to LeetCode to solve some SQL problems. There was an easy one that required using &lt;code&gt;CHAR_LENGTH&lt;/code&gt; to check the content length of a tweet and determine if it’s valid.&lt;/p&gt;

&lt;p&gt;That made me think: why would I even use &lt;code&gt;CHAR_LENGTH&lt;/code&gt;, or care that it exists, when I can just calculate the length in my application logic (like using &lt;code&gt;.Length&lt;/code&gt; in C#)?&lt;/p&gt;

&lt;p&gt;The answer is simple: in many real-world scenarios, you need to filter data in the database to avoid fetching huge amounts of unnecessary data into your application.&lt;/p&gt;

&lt;p&gt;Imagine a scenario where I want to check product descriptions. If a description is less than 50 characters, I mark it as low quality or exclude it from the results. What should I do?&lt;/p&gt;

&lt;p&gt;Fetch all products (imagine something like Amazon), then filter in my application?&lt;br&gt;
Or filter directly in the database using &lt;code&gt;CHAR_LENGTH&lt;/code&gt;, and only fetch what I actually need?&lt;/p&gt;

&lt;p&gt;The key measure here is not where the computation happens — it’s how much data is being transferred. An extra computation inside the database is far cheaper than moving millions of rows to your application and then filtering them.&lt;/p&gt;

&lt;p&gt;That said, I’m not saying everything should be done in the database. There are cases where filtering in the application makes more sense — for example, when the business logic is complex, or when the dataset is already small.&lt;/p&gt;

&lt;p&gt;PS: I’ve read that using functions like &lt;code&gt;CHAR_LENGTH&lt;/code&gt; can affect index usage, but I don’t fully understand the cost yet. I’ll read more about it, and if I form a solid understanding, I’ll write about it.&lt;/p&gt;

&lt;p&gt;I know this is a simple idea, but I wanted to get it out of my head and into words.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>database</category>
      <category>performance</category>
    </item>
  </channel>
</rss>
