Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      CodeSOD: A Unique Way to Primary Key

      July 22, 2025

      BrowserStack launches Figma plugin for detecting accessibility issues in design phase

      July 22, 2025

      Parasoft brings agentic AI to service virtualization in latest release

      July 22, 2025

      Node.js vs. Python for Backend: 7 Reasons C-Level Leaders Choose Node.js Talent

      July 21, 2025

      The best CRM software with email marketing in 2025: Expert tested and reviewed

      July 22, 2025

      This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

      July 22, 2025

      I’m a wearables editor and here are the 7 Pixel Watch 4 rumors I’m most curious about

      July 22, 2025

      8 ways I quickly leveled up my Linux skills – and you can too

      July 22, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025
      Recent

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025

      Zero Trust & Cybersecurity Mesh: Your Org’s Survival Guide

      July 22, 2025

      Execute Ping Commands and Get Back Structured Data in PHP

      July 22, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025
      Recent

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025

      “I don’t think I changed his mind” — NVIDIA CEO comments on H20 AI GPU sales resuming in China following a meeting with President Trump

      July 22, 2025

      Galaxy Z Fold 7 review: Six years later — Samsung finally cracks the foldable code

      July 22, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Just a Few Updates

    CodeSOD: Just a Few Updates

    July 17, 2025

    Misha has a co-worker who has unusual ideas about how database performance works. This co-worker, Ted, has a vague understanding that a SQL query optimizer will attempt to find the best execution path for a given query. Unfortunately, Ted has just enough knowledge to be dangerous; he believes that the job of a developer is to write SQL queries that will “trick” the optimizer into doing an even better job, somehow.

    This means that Ted loves subqueries.

    For example, let’s say you had a table called tbl_updater, which is used to store pending changes for a batch operation that will later get applied. Each change in updater has a unique change key that identifies it. For reasons best not looked into too deeply, at some point in the lifecycle of a record in this table, the application needs to null out several key fields based on the change value.

    If you or I were writing this, we might do something like this:

    update tbl_updater set id = null, date = null, location = null, type = null, type_id = null
    where change = @change
    

    And this is how you know that you and I are fools, because we didn’t use a single subquery.

    update tbl_updater set id = null where updater in
            (select updater from tbl_updater where change = @change)
    
    update tbl_updater set date = null where updater in
            (select updater from tbl_updater where change = @change)
    
    update tbl_updater set location = null where updater in
            (select updater from tbl_updater where change = @change)
           
    update tbl_updater set type = null where updater in
            (select updater from tbl_updater where change = @change)
           
    update tbl_updater set date = null where updater in
            (select updater from tbl_updater where change = @change)
           
    update tbl_updater set type_id = null where updater in
            (select updater from tbl_updater where change = @change)
    

    So here, Ted uses where updater in (subquery) which is certainly annoying and awkward, given that we know that change is a unique key. Maybe Ted didn’t know that? Of course, one of the great powers of relational databases is that they offer data dictionaries so you can review the structure of tables before writing queries, so it’s very easy to find out that the key is unique.

    But that simple ignorance doesn’t explain why Ted broke it out into multiple updates. If insanity is doing the same thing again and again expecting different results, what does it mean when you actually do get different results but also could have just done all this once?

    Misha asked Ted why he took this approach. “It’s faster,” he replied. When Misha showed benchmarks that proved it emphatically wasn’t faster, he just shook his head. “It’s still faster this way.”

    Faster than what? Misha wondered.

    [Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleWhatSie – WhatsApp web client
    Next Article Plasma Bigscreen: L’interfaccia TV basata su KDE ritorna con nuove funzionalità

    Related Posts

    News & Updates

    The best CRM software with email marketing in 2025: Expert tested and reviewed

    July 22, 2025
    News & Updates

    This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

    July 22, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Perficient is Shaping the Future of Salesforce Innovation

    Development

    WWE Cactus Jack x WWE Merchandise

    Web Development

    CVE-2025-2821 – WordPress Search Exclude Plugin Unauthenticated Data Modification

    Common Vulnerabilities and Exposures (CVEs)

    Leaked AMD Ryzen 5 X3D gaming CPU will dominate the market — and it could launch this year

    News & Updates

    Highlights

    Development

    What Security Leaders Need to Know About AI Governance for SaaS

    July 10, 2025

    Generative AI is not arriving with a bang, it’s slowly creeping into the software that…

    Introduction and Overview Microsoft 365 Admin Center

    April 15, 2025

    Git Interactive Rebase Tool – terminal-based sequence editor for interactive rebase

    April 26, 2025

    CVE-2025-29660 – Yi IOT XY-3820 Remote Code Execution Vulnerability

    April 21, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.