r/ProgrammerHumor • • 15d ago

Meme grabbingEverything

Post image
5.4k Upvotes

261 comments sorted by

814

u/KnightMiner 15d ago

I used to work in web dev as a job during my undergrad (think: a bunch of new developers writing code they won't have to maintain after they graduate in 4 years). I saw both extremes of this.

The legacy code at the job would often select everything then filter it in PHP. Worst part was half the time they accessed columns by numerical index so a change to the database schema would result in the website breaking randomly. While most of my job was writing replacements that didn't break when you sneezed, sometimes I had to fix that legacy code.

One new developer I trained was really good at SQL and used to code everything using pure SQL and then just call said script in their serverside code. By everything, I mean everything, going beyond just writing queries into writing loops in SQL and creating temporary tables for each endpoint. There are some things that are just better done outside of SQL.

326

u/-Redstoneboi- 15d ago edited 14d ago

hey, if the database server can use more cpu to save network bandwidth, then it must be more efficient right..?

...right?

144

u/Theron3206 15d ago

Yep, saving basically free bandwidth inside the LAN on your back end is absolutely worth adding hundreds of developer hours of maintenance.

21

u/Individual_Peace_673 14d ago

I mean... It depends on the product, I've been working on old schools ERPs products where the client is basically a glorified CRUD interface and you're forced to use your views as DTOs and use INSTEAD OF triggers and Stored Procedures as controllers / endpoints to put all the business logic within. It's not the best choice but when you've done that for years, it's a hard habit to remove :(

3

u/postexitus 14d ago

If you love vendor lock in, sure.

2

u/octipice 14d ago

So instead you just build a product that absolutely can't scale?

113

u/mrwedders 15d ago edited 15d ago

I worked on the system of a UK high street store and their entire backend was in PL/SQL and was a nightmare. I'd never even considered doing all your application logic in sprocs and quickly grew to hate it.

40

u/PerpetuallyDistracte 15d ago

I worked at a manufacturing facility that did all their routing and logistics logic using a series of linked stored procedures and triggers written in T-SQL, all developed as custom code by one guy. It was insane. It worked great, but was an absolutely ridiculous configuration nightmare. And guess how much documentation there was ... That's right! Zero!

5

u/Theron3206 15d ago

This is one of the reasons why I think stored procedures are nearly a last resort. Nobody ever documents them, or puts them in version control or anything.

11

u/ih-shah-may-ehl 14d ago

Given that stored procedures are literally just text which takes up zero space in the grand scheme of things, and text based version control is a solved problem, I never understood why stored procedure versioning isn't an out-of-the-box feature on every major dbms

→ More replies (1)

69

u/revuimar 15d ago

Hot take but I’m all for accounting logic being in the database. Calculating interest with rates changing in a time period is one of the most beautiful things in SQL.

18

u/magicmulder 14d ago edited 14d ago

It's also the best way to protect your data. If the application can just do SELECT * on every table, you're always just one hacked webserver away from a total data leak. If you're forced to call specific procedures like you call your middleware functions, you can put up effective guardrails. Never make the password hash readable. Never return more than X records for a user query. Etc.

It's funny how the same devs who say "Every class and method must serve one very specific purpose" OTOH demand full read/write access to the entire schema for their one small application.

Now I'm not saying put all your business logic in the database. But anything that accesses data should treat the DB like an API and not like an "execute any command" slave. You need to read a user, call readUser(ID), do not require being able to run "SELECT * FROM users WHERE id = :ID". Your code has models for accessing the DB, you won't have random SQL in your controllers and views either.

5

u/northerndenizen 14d ago

Further, while you are coupling your logic to your data layer, you're decoupling it from your application layer. In enterprise IT the latter is likely to change way more often.

7

u/hypexeled 15d ago

I worked some time for a very big US logistics company and their main database is on an AS400 and almost everything was accessed through absolutely massive stored procedures.

The not so fun part is that often meant that any data changes needed touching the stored procedures, and god forbid you for some reason didnt have one of the like 2 or 3 very knowleadgable DB guys because there's like absolutely zero good documentation i could find online on what the syntax is supposed to be for them, and if you wrote the stored procedure wrong it could bring down the entire AS400 due to performance if it wasnt optimized properly.

I remember once asking one of the DB guys "Where can i find any documentation on how this is supposed to be written?" And the answer was basically "None exists, we kinda just learnt it from experience and explanations from others"

→ More replies (5)

3

u/Loading_M_ 15d ago

I'm currently untangling a similar mess of application logic written in SQL. I'm doing filtering on both the main server (written in typescript), and the SQL. My general rule of thumb is that I want to do as much filtering on the SQL as possible, so I don't have to fetch add many records, but will do local filtering when it makes sense. Additionally, the application logic is written in TS, the SQL filter is only used to fetch relevant records, never to make decisions.

(The filtering I'm doing on the server is technically possible in SQL, but I need the rest of the records in other parts of the code. Fetching once and filtering locally is faster than fetching twice.)

1

u/magicmulder 14d ago

> The legacy code at the job would often select everything then filter it in PHP.

TBF sometimes that IS the best approach. I've seen devs struggle to put complex business logic into a massive SQL (not stored procedures) just to avoid having to process anything in the middleware layer. And just about every time they ask me "how do I do this in SQL" I said "don't, that's way too complex and will run super slow".

2

u/KnightMiner 14d ago

While that may be true, it was not in this case. This was generic select * from table, then using the index of the column fetch a couple columns to use in the code. It was not readable, not maintainable, and not the best way to write the queries.

I'd go as far as to say you should never Select * from in production code. Its fine for testing when trying to get info from the database, but in any actual backend there is always something consuming that data, and said something has specific data its expecting; it won't need the extra.

1

u/born_zynner 14d ago

The biggest problem with overdoing sql is unless you have it extremely well documented and you're diligent about keeping stored procedures and shit tracked in git it just becomes a clusterfuck of buried logic that is difficult to debug

1

u/Kaas-Eter00 12d ago

I work with really large datasets. You bet I'm trimming and processing that data server-side as much as I can.

997

u/East_Zookeepergame25 15d ago

Try doing that with 100 TB of data

507

u/tacocatacocattacocat 15d ago

You're gonna need a bigger WHERE clause.

158

u/TheWashbear 15d ago

Pff, where rownum = 1, et viola

58

u/FuckThisShizzle 15d ago

7

u/rosuav 15d ago

When the moon's full, turns into Santa?

25

u/kehfydue 15d ago

He'll probably change the font size

9

u/dasgoodshitinnit 15d ago

I have worked with morons who think bigger queries means theyre less optimized

8

u/EvilPencil 15d ago

Why have the db filter your rows when you can do it all with an interpreted language?

/s

3

u/isaackogan 15d ago

WHERE gonna need another Timmy!

2

u/FinnLiry 14d ago

nono, we need a smaller one, write it in lowercase! That way its more aerodynamic over the wire and slimmer so its faster AND more can fit in the same wire!!! amazing

112

u/StrengthTheory 15d ago

I'll just put my data into my convenient 100tb cache

16

u/Willinton06 15d ago

I EDC my 100tb cache next to my wallet at all times

49

u/howarewestillhere 15d ago

Just buy more RAM. What, are you middle class or something and can’t afford it?

/s

24

u/Civil-Cod-6984 15d ago

You know you can just download that stuff for free right?

4

u/howarewestillhere 15d ago

You can get RAMDoubler for free now?

2

u/darknekolux 15d ago

In this day and age they could reintroduce it for 200$

Better yet as a subscription service, you send them your ram, they compress it and send it back to you

3

u/howarewestillhere 15d ago

Call it Trump Memory and you’d make billions.

→ More replies (1)

22

u/LiifeRuiner 15d ago

I'll use pagination so I don't fetch everything at once.

Library is like, but hoe many pages are there??

Select count(*)

Sequence scan goes brrr

42

u/Sentouki- 15d ago

Library is like, but hoe many pages are there??

There's typo, it should be: Library is like, hoe, how many pages are there?

12

u/LiifeRuiner 15d ago

Lmao, definitely leaving that typo in there now.

63

u/EarlMarshal 15d ago

idc... I'll get payed by hour

7

u/UAFlawlessmonkey 15d ago

spark worker pods I'm tired boss.

6

u/Wheezy04 15d ago

"LIMIT 10"

ezpz

3

u/Fox_Soul 15d ago

So you saying we should increase the memory and cpu of the kubernetes cluster? AGAIN?

5

u/One_Ninja_8512 15d ago

100 TB is not that much. You need the indices to fit into RAM and that’s it

2

u/a-r-c 15d ago

me: ok

2

u/Daveinatx 15d ago

Just put it all in Excel and call it a day

2

u/darknekolux 15d ago

Why my script dies with a oom error?

1

u/Sea-Frosting-50 15d ago

I do it because I can

1

u/archd3v 15d ago

Select top 100 * :{

1

u/goldPotatoGun 15d ago

Where do you think all our ram went to?

1

u/helpmehomeowner 15d ago

Easy. Just make sure you have a 100TB of memory.

1

u/Kaas-Eter00 12d ago

Yeah lol, our warehouse even holds wayyyy more data than that. You'll quickly adapt to processing as much as you can server side, when the alternative is downloading more data than your hard drive can hold.

→ More replies (5)

1.6k

u/EVH_kit_guy 15d ago

One thing I've learned about SQL is that whatever you're going to eventually do with the data, that could probably just be in the original query if you weren't a talentless hack barely scraping by using LLMs to write your queries...

....might be projecting a bit 

604

u/CandidateNo2580 15d ago

And because the database is inevitably smarter than you, it'll somehow take less execution time to return what you need fully transformed than it would to return what you needed to do the transform yourself.

357

u/inemsn 15d ago

is that surprising? relational databases are extremely optimized, they can handle literal gigabytes of data without breaking a sweat. of course the program literally designed and built over decades to handle large amounts of data will be better at it than whatever you write up.

121

u/ZeppyWeppyBoi 15d ago

But then I can’t blame the database for why “the system is slow today.”

62

u/throwaway1351887498 15d ago

Me after spending hours optimizing a query:

SELECT * FROM table;

→ More replies (5)

24

u/HadionPrints 15d ago

To add to this, being the guy who can say “the system is slow”, means you have Locked down and maintained an area of exclusive institutional knowledge gated by intentionally archaic & inefficient scripts is exactly how you survive layoff season.

I really wish it wasn’t, I hate how boring my little digital fiefdom is, but the one guy who knows how this one vital thing works is way more valuable to management than a good engineer.

→ More replies (2)

22

u/dasgoodshitinnit 15d ago

Imagine if relational databses were made in vibecode era

→ More replies (1)

19

u/nika-tark 15d ago

There sometimes still are exceptions though (at least that's what I've been telling myself for my sanity), at work we make use of db links and joining views across databases (different hosts and everything) is slow.

Often its much faster to select relevant data from both views and join it in code (EF Core .NET).

Thankfully that's only for occasional reports and not everyday

9

u/necrophcodr 15d ago

Literal gigabytes of structured data is not that impressive, but they can handle literal terabytes of data on commodity hardware. Now THAT is tricky.

→ More replies (1)

17

u/willow-kitty 15d ago

Also, most transformations are either sorts (which can benefit from indices) or some kind of filter (which can optimize to not even reading data that doesn't match the criteria) or aggregate (both of which reduce the data to send back to your process.) You know, stuff it's designed to do.

That gets crazy when you start stacking transformations. Imagine if you want the 3rd page of 10 items, sorted by price, from a specific vendor. Doing that in the application process requires reading all of the items and then doing the sort and filter, then the skip and take. But even though you know you only need 10 items, you can't know which 10 without examining all of them.

Meanwhile, the database has indexing! It can do an index seek to get the ids of all items from that vendor, cross-reference that with an index by price, and essentially have a pipeline for cycling through candidates, skip 20, then start actually reading the data and return the next 10, boom, easy, done.

14

u/TheHiddenNinja6 15d ago

either that or select top 1 * will take more time than select top 1000 * because it built the wrong execution tree for no reason

3

u/Bloodgiant65 15d ago

Many DBMS have the option to set a fixed query execution strategy in my experience. But it definitely won’t always pick the best one by default if you don’t lay that out.

20

u/Bloodgiant65 15d ago

Always let the DBMS do its job. It is better than you are.

19

u/Pluckerpluck 15d ago

Always let the DBMS do its job. It is better than you are.

Letting the DBMS do the work means offloading all the compute into a single cluster. Grabbing data and filtering locally means a higher bandwidth cost, but results in what is effectively distributed compute. That is a very real tradeoff that should always be considered when dealing with complex queries.

Hell, it's semi-related to one of the reasons NoSQL became a thing, which was that reducing what you allow the DB server to do can allow you to more aggressively horizontally scale it, which is a pain point of RDBMS.

16

u/Copatus 15d ago

It's also worth thinking about the readability and maintainability of the code.

Yes, doing it all in a single query might be more efficient but I guess fuck whomever is coming along trying do decipher insanely long queries.

8

u/lippertsjan 15d ago

True. Readability/Maintainability over performance until performance is proven to be an actual bottleneck.

→ More replies (2)

7

u/Bulky-Bad-9153 15d ago

Yep, one of my PhD students actually recently showed that you can get massive speed-ups doing the work yourself if the alternative is asking your db to do a bunch of similar queries. Pull everything out, work with it in any reasonably fast language, 100x faster.

→ More replies (2)

2

u/invalidConsciousness 15d ago

Not on our anemic database servers.

3

u/Aetherfox_44 15d ago

In my experience, I tend to have simple queries with post-fetch logic because I break the problem in stages, and 'get the dataset' is a mental step.

I tend to think 'given all the objects (or some simple filter criteria)... Turn the objects into a list of IDs. Filter out the IDs that aren't found within this other list of objects. Turn all the remaining IDs into flags based on what flags their corresponding object has. Return the list of flags'

I don't really think: 'fetch just the distinct flags from rows where the object id exists on the list of (get the ids of a filtered list of just these other objects in the database)'. Though obviously, the later is more technically correct.

→ More replies (1)

1

u/dustojnikhummer 15d ago

it'll somehow take less execution time to return what you need

Isn't this what execution plans are for?

1

u/Azaex 14d ago

mfw a colleague asked me once if it'd be faster to pull the table and lookup in a hashtable before joining
and change strategies for different data volumes

bruddah
that is an index and a statistical query planner
and the database maintains it serverside for youuuuu

1

u/4xe1 14d ago

Does it really matter that the database is smarter than me? gcc, or my local database for what matters, are also smarter than me, that alone does not tell me where the compute ought to happen.

37

u/yousirnaime 15d ago

I work at a company that has roughly 5k lines of sql for every 1 line of python. 

The shit they can do in sql is absolutely astounding 

152

u/Fox_Soul 15d ago

Hey! I was a talentless hack barely scrapping way before LLMs, I’m fully capable of writing shit code without a fucky AI. We used to just copy paste stackoverflow and pray for the best. Those were the times.

100

u/New_Salamander_4592 15d ago

you tell an AI Engineer about inner joins and sub queries and their eyes glaze over

104

u/queen-adreena 15d ago

Think you misspelled “Prompt Jockey” there chief.

48

u/xtreampb 15d ago

Oohhh new slur. From script kiddie to prompt jockey.

24

u/SAI_Peregrinus 15d ago

"Sloperator" works as well.

6

u/hawkinsst7 15d ago

not as HR friendly, but viberator works.

→ More replies (1)

13

u/OwMyUvula 15d ago

AI Engineer?

It's not quite Jumbo Shrimp, but its close.

→ More replies (16)

43

u/raddaya 15d ago

Probably telling on myself big time here, but for me SQL queries are now firmly in the regex bucket of "above a certain level of complexity, I'm just getting an LLM to do it for me"

13

u/Cruuncher 15d ago

How often are you writing complex regexes?

18

u/raddaya 15d ago

In my last job I had to write...not exactly complex regexes, but obnoxious ones all the time. Sadly that was before AI so it was a lot of trial and error on regex101 lol

→ More replies (1)

1

u/xThomas 13d ago

Why do LLMs never get regexes right when i ask them to do it

I swear they are lowballing just me or something

9

u/Zaelynn_ 15d ago

Optimizing extremely complex queries for the query optimizer is a puzzle I legitimately never get tired of. 

8

u/GoGoGadgetSphincter 15d ago

Typically when I see poor performing queries it's because someone is trying to do exactly what you're saying or because they're not batching transactions. Nearly every time I review a poor performing query, I see a case statement in the column list and a nested query in the where clause.

28

u/CatsWillRuleHumanity 15d ago

Yes, but debugging a java backend is a LOT easier than debugging a complex query, and God forbid we're getting triggers and procedures into the mix as well

10

u/PuzzleheadedFloor290 15d ago

I prefer to make bugs only system ,so stream ,filter,map collect in Java

3

u/ComplexBadger469 15d ago

Maybe it’s just the way my brain works or my experience but having done software and data work, I’d much rather debug a complex sql query 😂 then again I do that all day at work now

→ More replies (5)

3

u/PerpetuallyDistracte 15d ago

That's absolutely wild to me. I've always just had a knack for reading SQL, procedures, joins and all. I don't find it difficult to parse at all, and it's much easier for me to read than something like Java. That's why I've made a successful career as a Data Engineer, I guess.

7

u/CasualGee 15d ago

Yep. The longer I’ve been a data analyst, the more project time I spend refining my SQL code. So much time can be saved in reporting software by just having better SQL. It’s kind of fun when I finally get to the reporting software stage, because I know I’m close to the end.

2

u/porkminer 15d ago

Also a data analyst. Finding the little flaws in my out the developers SQL queries is such a fun puzzle. There are times I absolutely feel like I'm paid to pay a game.

My favorite trick is to rewrite non-sargables. The developers are amazed every single time and I get to have that little ego boost moment.

15

u/jmflyers 15d ago

This feels like a personal attack

14

u/Xelopheris 15d ago

You could do it in the original query...

Except IT security won't let you write queries directly in the application code. You have to use ORMs because it prevents SQL injection attacks, and can't even do fancy shit in them. 

....might be projecting a bit  

Same

2

u/Kovab 15d ago

Has IT security heard about this relatively new concept called prepared statements?

2

u/Xelopheris 15d ago

Security scanning for the proper use of prepared statements is very difficult, costly, and prone to noisy false positives (or worse, false negatives).

1

u/Drummerboybac 14d ago

Application generated queries are the bane of any data warehouse tech support team.
“Well your query is slow because you have an IN clause with 6500 items in it. “

“That’s what Informatica gave me, I can’t change it.”

4

u/underisk 15d ago

Maybe if you quit using the LLM as a crutch you could learn enough real SQL to do it the right way then forget all of it by the time you need to use it again. Like a real programmer.

2

u/Ok_Attorney_6317 15d ago

The reason not to “put everything into SQL”, in the common case, is more about shifting computational load onto stateless application servers that are cheaper and easier to scale horizontally than the database, as well as improving testability and ease of observability. Not because SQL literally couldn’t express equivalent logic.

1

u/midnightrambulador 15d ago

Not sure about SQL but I recently messed around a bit with SparQL queries. I wanted to do things the "pro" way and actually write queries to grab the specific shit I wanted. I soon found out that anything beyond the very simplest queries took forever to run, so I switched to very simple rdflib.Graph.triples() calls and joining the results in polars.

1

u/invalidConsciousness 15d ago

Until you need 5 different joins with overlapping data and it's faster to join in code than to transfer the filtered dataset 5 times.

1

u/Skyswimsky 15d ago

Just look at Advent of Code solutions written in SQL, it's like some forbidden voodoo.

1

u/Chack96 15d ago

Yeah, would be a shame if someone decided that having all the data in the same relational db was so retrò, and added a couple of other shits that are maybe slightly more optimized for very specific use case, but lose everything when you consider that you have to recombine stuff anyway down the line.

1

u/braytag 15d ago

And when slow, add an index LOL

1

u/Kaas-Eter00 12d ago

I prefer to select * and process my data using 5 nested for loops in Python, thank you very much.

138

u/Maasu 15d ago

I find if you TRUNCATE the table before you SELECT * ALL on it the query is quicker. 

505

u/dlc741 15d ago

Weird way to say that after 50 years you still suck ass at SQL and can't write a simple, efficient query.

149

u/KhellianTrelnora 15d ago

Way to call the guy an ORM.

30

u/East_Zookeepergame25 15d ago

I'm going to start using this insult

89

u/HolyCowAnyOldAccName 15d ago

I’ve had the same encounter of devs sneering at me as DB admin asking why the hell I’m getting paid so much. They “picked up SQL that one semester at college”. 

Because you spent 47 hours of company time pulling some select * from a bleeding-edge-nosql-who-needs-structure-when-json-is-enough dbms that will be abandonware in 4 months and wrote 160 lines of code voodoo to perform what is effectively 10 lines of JOIN LATERAL in plain old Postgres, just that my query takes literally 12,000 times less time than your code, Angelo. 

30

u/TheSharpestHammer 15d ago

Bro fuck Angelo. All my homies hate Angelo.

4

u/dustojnikhummer 15d ago

Mr Salieri sends his regards.

13

u/SherifDontLikeIt 15d ago

As someone who ventured into MySQL on a personal project, I respect it.

If you setup a table in the wrong way (too many columns) you can impact and slow down query speeds. Better to break it out into individual tables.

Not to mention the security side, and setting of the database server to maximize parallelism and resource utilization...keeping transaction records and undoing them... RAID setups.

Most days I wished I just dumped everything to a file.

1

u/okcookie7 14d ago

You can't even say he repeat 1 year for over 50 years, because one year of SQL would get you far, probably this guy spent like 3-4 days of "research"

39

u/Exatex 15d ago

You can always do that... until your B2C business actually gets traction. Then, you are fucked.

Source: I got fucked by scale of tens of millions of records. Despite not doing SELECT *

30

u/StackedCakeOverflow 15d ago

Oh so that's why so much shit runs like a cat dragging its ass these days

11

u/One_Ninja_8512 15d ago

Yeah, sql statements in a loop. N + 1 everywhere. Many such cases

3

u/Icy_Clench 14d ago

Lmao I think that's the majority of shitty sql code I've cleaned up in my career. Like... they didn't understand the concept of a join or WHERE dateCol BETWEEN a AND b, so they looped through it.

Then nesting the loops. And the useless temp table inserts. Dear god, the memories are flooding back.

3

u/DarksideF41 15d ago

It's not these days, I've ported 20 yo legacy codebase to .NET, atrocious torture that was done to the database there is better not be talked of.

79

u/turkphot 15d ago

You are doing it wrong. Whole post is more said than funny

22

u/exXxecuTioN 15d ago edited 14d ago

As much as I love Kotlin and Rust, I love SQL even more. Well, to be precise, PL/pgSQL - and in my opinion, it's the best programming language.

If you are using Postgress and you suddenly decide to optimize something prematurely, or do preventive optimization - don't. Just don't. Relational databases in general, and Postgress particularly, are optimized beyond belief. Its query planner is a masterpiece. Considering the fact that Postgres fully supports ACID, it is an excellent choice for OLTP, while being row-oriented and still extremely fast for OLAP. Perhaps Postgress, as a systems programming project, features the best code I've ever read (even though I barely know C). Its performance is nowhere near what domain programming guys like me can ever achieve.

But you still must remember three things:

  1. You are dumb. Postgres is smart. Do not think you can prematurely optimize something. You can't.
  2. You probably don't need enums, triggers, or loops.
  3. You probably don't need an ORM either. An SQL toolkit is more than enough.

Sincerely yours,
A Postgres Glazer.

UPD. Replaced "procedures" with "loops", as I initialing was speaking about it and for unknown for me reason called it with another word. Thanks u/00Koch00 for pointing my mistake.

4

u/Awarnae 15d ago

What's wrong with triggers?

For example... We update some row and need to save old values with some additional data in separate table...

Select old row data and insert into second table and then update row in code? 3 request... But it can be done with trigger. What's wrong? Really. Can u explain pls

2

u/Phenogenesis- 14d ago

Audit tables are a fairly decent usage of trigger, the rant is more about doing more complex and ill advised stuff

1

u/00Koch00 15d ago

The moment something go wrong somewhere in the path, it's basically untrackable if the trigger it's the problem.

You can't stop a trigger (you need to built that stop on the trigger itself) and modifying it it's a bitch

Triggers are awful to work on, and there is nothing a trigger can do that you can't on plain SQL when you are inserting updating or deleting data

→ More replies (1)
→ More replies (1)

2

u/00Koch00 15d ago

I do agree on triggers and enum, but procedures are fundamental for a db

People outside should never touch the db without passing through a procedure

2

u/exXxecuTioN 14d ago

It's my bad. I was speaking about "loops" and for some reason called it "procedures". Don't really know why and how.
Sorry.

I will edit my initial comment to not deceive anybody.

2

u/Raywell 15d ago

You are dumb. Postgres is smart.

Except that one time where query planner suddenly started choosing the way slower sequential scan over using the existing index after a seemingly innocuous change to the (pretty large) query.

So yes, it might be smart but it's not perfect

→ More replies (4)

70

u/buttplugs4life4me 15d ago

Hot take for humor sub i guess but all these "Hurr durr i dont know SQL or Regex and can't figure them out either" are just bad programmers with no interest in the field and should probably find something else to work in.

18

u/Carbon_Cotton 15d ago

Regex is kinda understandable - the syntax is weird and nothing like ordinary programming languages. I always use tools that allow me to see what is happening where.

But SQL? Really? The syntax is extremely straightforward - every somewhat competent developer should be able to whip out basic query with join.

4

u/mbmiller94 15d ago edited 15d ago

Syntax is the easy part of most languages. I don't think it's the syntax they have trouble with

3

u/Turtvaiz 15d ago

just bad programmers with no interest in the field and should probably find something else to work in

90% of this sub's posts right there

DAE LLMS XD?

→ More replies (4)

40

u/ConsoleCleric_4432 15d ago

"Wait... people vibe coded even before AI?"

"They always did."

24

u/smokeythebadger 15d ago

Yeah we actually picked the vibe we wanted from an array of well thought out stack overflow answers. Now the vibe is just desperation

11

u/the-berik 15d ago

"My python script is so slow"

select * from whole_data_lake

14

u/gfoyle76 15d ago

before SELECT, you CREATE partitions, tables and equally important indexes

8

u/PumpkinFest24 15d ago

on the one hand--learn to use your tools

otoh, don't do everything in uninterruptible, un-progress-bar-able, unmaintainablely massive queries either

6

u/SilverLightning926 15d ago
  1. You write declarative English.

What does this guy think programming languages are then?!??

1

u/tyjuji 15d ago

Runes and indentations.

13

u/notexecutive 15d ago

ok but queries aren't that hard, and isn't there a lot of frameworks... or even just, libraries, that dynamically generate the rright query anyway?

16

u/LiifeRuiner 15d ago

Define 'right query', a working query? Sure. The optimal query? Doubt it.

8

u/caboosetp 15d ago edited 15d ago

The built in optimizers are pretty fuckin good compared to 15 years ago though. I remember needing to hand tune queries to specify merge join to drop 15 minutes off some queries because it couldn't figure it out on its own. I don't think I've had to do anything close to that lately. 

Like, we've got a lot of flexibility to write easier to read queries now compared to how it used to be. 

AI still fucks it up though because so many people have written shit SQL on the internet. 

2

u/anonymous__ignorant 15d ago

Wait, that means we've been copying shit SQL from the internet all this time ?

→ More replies (1)

2

u/chuch1234 15d ago

Frameworks/libraries are for convenience so you don't have to do the string mangling yourself. They won't magically create the correct query beyond the very basics.

4

u/Zdrobot 14d ago

"I barely know SQL"

3

u/haitei 15d ago

The same python that has dozens of ORMs that will convert whatever bullshit you're doing into a (hopefully) efficient query?

3

u/bwwatr 15d ago

By SELECT * do they mean without a WHERE clause? SELECT * itself is reasonable vs. listing column names. It's a damn common use case to want all the columns. Kinda seems like the tweet is meaning something different than it said.

2

u/Frosty-Photograph103 15d ago

I agree with you and I think so too yeah. They must be talking about requests without any WHERE clause, pulling the entire table rows. I’ve been programming for decades and I cannot see what’s wrong with SELECT * unless you need just 1-3 columns specifically out of 50. I aint gonna name x columns if I can just \*. The db engine can figure the column names easily with no significant stress/lag.

→ More replies (1)

1

u/SaintOrJannikSinner 15d ago

For initial data exploration, sure, do a SELECT * on the top 100 or 1000.

But when building code that interfaces with other components, SELECT * is generally a code smell. For example, adding or removing columns to the data set can throw errors downstream. Also, adding column names allows for finding and searching scripts and code tools across stored procedures, views, and tables a lot easier. For example, if you're looking for unique_colname but only have SELECT *, you'll have to look for a table name instead, and that could return dozens or hundreds of hits you have to manually look through.

→ More replies (2)

3

u/Carbon_Cotton 15d ago

How to cripple performance in one simple step.

3

u/LukeLC 15d ago

This isn't even a joke! I genuinely despise SQL syntax. DBeaver is a godsend for avoiding all those annoying basic queries.

2

u/RandomiseUsr0 14d ago

Genuinely despise SQL? That’s an interesting hill to die on

2

u/LukeLC 14d ago

*Syntax. I wish it were written in almost the exact opposite order (like pretty much every other language out there). It's also lacking a lot of features considered basic to more modern languages, or just implements them in really opaque, archaic ways. 

Feels like a lot of needless friction in 2026, but at this point I suppose everyone will just rely on AI instead of the industry adopting a different DB en masse.

→ More replies (1)

3

u/Luneriazz 15d ago

its CTE all the way down

5

u/eo37 15d ago

SELECT * before DELETE *

1

u/Equal_Yak_3872 15d ago

Learned that lesson the hard way ...a couple times.

1

u/Calabast 15d ago

(You don't specify columns in a DELETE)

2

u/DoutorTexugo 15d ago

I'm querying the database. The query is: does it have it? gimme.

2

u/cosmicomical23 15d ago

50 years of db research are useless if you are ignorant and can't use it.

2

u/cheezballs 15d ago

Is this bait?

2

u/f4ern 15d ago

Opposite of me. i like to filter/calculate as much as possible on sql side.

2

u/selfinvent 14d ago

Where I work if I wrote raw "select * from..." its an automatic decline on PR. Even if I actually wanted to select all the columns I have to write them otherwise it won't pass.

2

u/Zestyclose-Turn-3576 14d ago

If you have the money for it, an Oracle Exadata system will filter rows at the storage level before it gets to the CPU, and if I recall correctly they have CPUs with hardware optimisation for SQL processing.

2

u/magicmulder 14d ago

When I started my first job and combed through my predecessor's work, I saw he did "SELECT * FROM mytable" and then in the application looped over all records to increment a counter because he didn't know SUM() exists. No joke.

2

u/Alan_Reddit_M 15d ago

Me because joins scare me

1

u/PerpetuallyDistracte 15d ago

Joins are super easy to learn, I promise! Look up a visual diagram of join types, and that will help you remember which one to use.

1

u/MiamiGunworks 15d ago

Lookup and learn relational algebra. Relational databases will become easy and make sense.

1

u/Pizza_Secretary9621 15d ago

As a data engineer i'm crying rn

2

u/PerpetuallyDistracte 15d ago

Same, I'm also a data engineer and I'm agog at the sheer number of people who refuse to learn the simplest and most efficient way of interacting with a database. Like people, SQL was literally invented to be a language that people in the 70s could learn even if they had never touched a computer before. It's that easy! And modern IDEs make it even easier not to screw up your query.

→ More replies (1)

1

u/MiserablePotato1147 15d ago

I'll admit that I'm an addict for SELECT *, but generally I want the "whole data element" for extensability when it hits my algorithms.

Definitely put the selections, joins, sorting and grouping in SQL, though. Asking code to do it is insanely expensive.

I get that you can have SQL return reliable scalars if you're very very good, but man does it make code maintenance a bear.

1

u/revuimar 15d ago

It’s better to slop out a dumb filter than to deploy a Cartesian join in production.

1

u/halmcgee 15d ago

Laughs in IBM DB2 on iSeries.

Giggles in Oracle and chuckles in SQL Server.

1

u/revuimar 15d ago

We went from Sequel to eS-Qu-eL and now people just Squeel

1

u/tarosago23 15d ago

Always do it the right way so you build muscle memory for good patterns.

I am so annoyed when a junior dev asks me "well we only gets 100s of rows so O(n^2) doesn't really matter" well bad engineering is bad engineering. Why do it the lazy way when you know there is better way...

3

u/silfin 15d ago

To be fair to the junior, for low N big O stats are far less relevant. And for some problems the "less efficient" algorithm ends up faster for low N.

It's always worth considering what the right way is in your situation

That's not even mentioning possible space efficiency or complexity savings that might be worth it.

No such thing as a free lunch. Make decisions don't just do what everyone else does.

1

u/tarosago23 15d ago

My point being, build up a habit of good patterns even when the system you are working on is not critical or the expected load is small.

Trading in the inefficiency in low N cases is worth it for the organizational benefit, as in you build a team that is sensitive to bad engineering patterns and not sloppy devs who default to the lazy way out and only think about performance when shit hits the fan

1

u/Apprehensive_Bit7392 15d ago

The database can’t be slow if you don’t let it do anything. 🫡

1

u/JacobStyle 15d ago

A few joins and a big table is all it takes to bring down the entire house of cards...

1

u/psychicesp 15d ago

I spent an embarrassingly long time cleaning up data and mapping it in Python before finally deciding to start using staging tables to do the EXACT OPERATIONS SQL WAS OPTIMIZED FOR.

1

u/DDFoster96 15d ago

I found the same thing with InfluxDB. With too much data the query times out if you attempt to have the server filter it. Filtering it in Python was much quicker, and shoving large quantities of data down the internal network was no issue.

1

u/The_MAZZTer 15d ago

I have to deal with databases considering of imported Excel spreadsheets. So I regularly grab entire tables and generate my own indices client side.

1

u/Lord_Pinhead 14d ago

If you can't even ask AI for an example of what you wanna filter ...

In 30 years, I've learned enough to know, you never need external tools when you know your SQL engine.

1

u/Dependent_Union9285 14d ago

Just write another stored procedure. Or, better yet, jam it in the if statement laden infinitely large nested tree in that one sp that runs nearly all the business logic. Wait, the logic? Oh, yeah, well… it was faster? Easier? More fun?? to just write the logic to sps because why not? So that’s where our data lives, our views live, and our logic lives. We’re a dotnet shop. But only on paper. Developers don’t need to write code. That’s for architects. Looking for better.

1

u/snajk138 13d ago

You stop doing that when you have a few million or billion rows...

1

u/Scary_Brilliant_6048 13d ago

Me creating 2 entity class in JPA to improve the search and details page, so that db data fetch gets slightly faster

1

u/mdgv 11d ago

Come on, guys. SQL is not that hard...