Lädt...


🔧 CodeSOD: Hall of Mirrors


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: thedailywtf.com

Robert was diagnosing a problem in a reporting module. The application code ran a fairly simple query- SELECT field1, field2, field3 FROM report_table- so he foolishly assumed that it would be easy to understand the problem. Of course, the "table" driving the report wasn't actually a table, it was a view in the database.

Most of our readers are familiar with how views work, but for those who have had been corrupted by NoSQL databases: database views are great- take a query you run often, and create it as an object in the database:

CREATE VIEW my_report
AS
SELECT t1.someField as someField, t2.someOtherField as someOtherField
FROM table1 t1 INNER JOIN table2 t2 ON t1.id = t2.id

Now you can query SELECT * FROM my_report WHERE someField > 5.

Like I said: great! Well, usually great. Well, sometimes great. Well, like anything else, with great power comes great responsibility.

Robert dug into the definition of the view, only to find that the tables it queried were themselves views. And those were in turn, also views. All in all, there were nineteen layers of nested views. The top level query he was trying to debug had no real relation to the underlying data, because 19 layers of abstraction had been injected between the report and the actual data. Even better- many of these nested views queried the same tables, so data was being split up and rejoined together in non-obvious and complex ways.

The view that caused Robert to reach out to us was this:

ALTER VIEW [LSFDR].[v_ControlDate]
AS
SELECT
GETDATE() AS controlDate
--GETDATE() - 7 AS controlDate

This query is simply invoking a built-in function which returns today's date. Why not just call the function? We can see that once upon a time, it did offset the date by seven days, making the control date a week earlier. So I suppose there's some readability in mytable m INNER JOIN v_ControlDate cd ON m.transactionDate > cd.controlDate, but that readability also hides the meaning of control date.

That's the fundamental problem of abstraction. We lose details and meaning, and end up with 19 layers of stuff to puzzle through. A more proper solution may have been to actually implement this as a function, not a view- FROM mytable m WHERE m.transactionDate > getControlDate(). At least here, it's clear that I'm invoking a function, instead of hiding it deep inside of a view called from a view called from a view.

In any case, I'd argue that the actual code we're looking at isn't the true WTF. I don't like this view, and I wouldn't implement it this way, but it doesn't make me go "WTF?" The context the view exists in, on the other hand, absolutely does. 19 layers! Is this a database or a Russian Honey Cake?

The report, of course, didn't have any requirements defining its data. Instead, the users had worked with the software team to gradually tweak the output over time until it gave them what they believed they wanted. This meant actually changing the views to be something comprehensible and maintainable wasn't a viable option- changes could break the report in surprising and non-obvious ways. So Robert was compelled to suffer through and make the minimally invasive changes required to fix the view and get the output looking like what the users wanted.

The real WTF? The easiest fix was to create another view, and join it in. Problems compound themselves over time.

[Advertisement] Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.
...

🔧 CodeSOD: Hall of Mirrors


📈 48.4 Punkte
🔧 Programmierung

🔧 CodeSOD: Hall of Mirrors


📈 48.4 Punkte
🔧 Programmierung

📰 KickassTorrents’ Mirrors Appear online with Petition for Artem Vaulin Release


📈 19.97 Punkte
📰 IT Security

📰 The best AI tech of CES 2025: Neural wristbands, smart mirrors and more


📈 19.97 Punkte
📰 IT Nachrichten

📰 Pacman-mirrors 4.16


📈 19.97 Punkte
🐧 Unix Server

📰 Cryptocurrency’s Infrastructure Power Grab Mirrors Russian Playbook


📈 19.97 Punkte
📰 IT Security Nachrichten

📰 'Algorithms Are Like Convex Mirrors That Refract Human Biases'


📈 19.97 Punkte
📰 IT Security Nachrichten

🐧 opinions / sanity-check please re this storage setup (RAID1 + btrfs + rotating air-gapped mirrors)


📈 19.97 Punkte
🐧 Linux Tipps

📰 KickassTorrents’ Mirrors Appear online with Petition for Artem Vaulin Release


📈 19.97 Punkte
📰 IT Nachrichten

📰 Book Review: A Misinformation Researcher’s Guide to the ‘Carnival of Mirrors’


📈 19.97 Punkte
📰 IT Security Nachrichten

📰 Pacman-mirrors 4.15


📈 19.97 Punkte
🐧 Unix Server

📰 FTP limited on mirrors.kernel.org


📈 19.97 Punkte
🐧 Unix Server

📰 Systemanforderungen: Mirrors Edge Catalyst empfiehlt acht CPU-Threads


📈 19.97 Punkte
📰 IT Nachrichten

🔧 The Harmony of Code and Music: How The TB-303 Sequencing Mirrors Software Engineering


📈 19.97 Punkte
🔧 Programmierung

📰 Should Cameras Replace Car Mirrors? US Regulators Want To Know


📈 19.97 Punkte
📰 IT Security Nachrichten

📰 Don’t be Fooled By U.S. Smoke and Mirrors on the Crime of Aggression


📈 19.97 Punkte
📰 IT Security Nachrichten

🐧 From 1 to 400 mirrors; The AlmaLinux Mirror System Story


📈 19.97 Punkte
🐧 Linux Tipps

🐧 Share your mirrors that are properly secured to a high-level with TLS encryption!


📈 19.97 Punkte
🐧 Linux Tipps

🐧 Update your mirrors and keyrings in your VMs and main systems


📈 19.97 Punkte
🐧 Linux Tipps

📰 From 1 to 400 mirrors; The AlmaLinux Mirror System Story


📈 19.97 Punkte
🐧 Unix Server

🕵️ VirtualBox 6.0.10 for Windows - Alternative mirrors


📈 19.97 Punkte
🕵️ Hacking

📰 The 5 best workout mirrors of 2023


📈 19.97 Punkte
📰 IT Nachrichten

🎥 Introducing the Private Mirrors App


📈 19.97 Punkte
🎥 Video | Youtube

📰 Best Yify Proxy Torrents And Mirrors


📈 19.97 Punkte
🖥️ Betriebssysteme

📰 [Testing Update] 2022-12-23 - Thunar, Screenshooter, XFCE-Settings, pacman-mirrors


📈 19.97 Punkte
🐧 Unix Server

🎥 DEF CON 26 AI VILLAGE - Aylin Caliskan - The Great Power of AI Algorithmic Mirrors of Society


📈 19.97 Punkte
🎥 IT Security Video

📰 A 26-Year-Old Inventor Is Trying To Put Mirrors In Space To Generate Solar Power At Night


📈 19.97 Punkte
📰 IT Security Nachrichten

🔧 How airport design mirrors software design


📈 19.97 Punkte
🔧 Programmierung

🐧 Are there any mirrors or magnet links for Zorin?


📈 19.97 Punkte
🐧 Linux Tipps

📰 APT-Like Phishing Threat Mirrors Landing Pages


📈 19.97 Punkte
📰 IT Security Nachrichten

🐧 Amazon Cloud Traffic Is Suffocating Fedora's Mirrors


📈 19.97 Punkte
🐧 Linux Tipps

📰 Mitsubishi Electric Believes Its AI-enhanced Camera Systems Will Make Mirrors on Cars Obsolete


📈 19.97 Punkte
📰 IT Security Nachrichten

🐧 Is it possible to host/seed Mirrors/ISOs ?


📈 19.97 Punkte
🐧 Linux Tipps

matomo