Does /g/ care about DB performance? - /g/ (#105675719) [Archived: 841 hours ago]

Anonymous
6/23/2025, 1:04:08 AM No.105675719
Performance
Performance
md5: a4ee846c2fe2970f61eb631c24519c0f🔍
Do you care and optimize your Databases for performance?
Replies: >>105675731 >>105675789 >>105676166 >>105678169 >>105679672 >>105679723 >>105679767 >>105680021 >>105680212 >>105680365 >>105680493 >>105680532 >>105681040 >>105682669
Anonymous
6/23/2025, 1:06:01 AM No.105675731
>>105675719 (OP)
I do if there was a performance issue but otherwise I could give less of a shit.
Replies: >>105675735 >>105675749
Anonymous
6/23/2025, 1:07:03 AM No.105675735
>>105675731
*couldn't
Anonymous
6/23/2025, 1:07:59 AM No.105675746
not doing basic DB queries correctly is one of the best indicators of a shitdev
Replies: >>105676455
Anonymous
6/23/2025, 1:08:54 AM No.105675749
>>105675731
the right answer
Anonymous
6/23/2025, 1:15:36 AM No.105675789
>>105675719 (OP)
That query is a non sense becase you can't use it to do pagination.
Replies: >>105675868 >>105679795
Anonymous
6/23/2025, 1:27:52 AM No.105675868
>>105675789
You can and you still don't need to query the entire database, by using:

View:
from django.views import generic
from .models import Question

class IndexView(generic.ListView):
template_name = "polls/index.html"
context_object_name = "latest_question_list"
paginate_by = 5 # This tells Django to paginate and show 5 items per page

def get_queryset(self):
# Return the full queryset, Django's Paginator will handle the slicing
return Question.objects.order_by("-pub_date")


Template:
{% if latest_question_list %}
<ul>
{% for question in latest_question_list %}
<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
{% endfor %}
</ul>

<div class="pagination">
<span class="step-links">
{% if page_obj.has_previous %}
<a href="?page=1">&laquo; first</a>
<a href="?page={{ page_obj.previous_page_number }}">previous</a>
{% endif %}

<span class="current">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
</span>

{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}">next</a>
<a href="?page={{ page_obj.paginator.num_pages }}">last &raquo;</a>
{% endif %}
</span>
</div>
{% else %}
<p>No polls are available.</p>
{% endif %}
Replies: >>105676180 >>105676231
Anonymous
6/23/2025, 2:20:42 AM No.105676166
>>105675719 (OP)
As if wrangling SQL to do complex queries wasn't already hard enough.
Anonymous
6/23/2025, 2:25:39 AM No.105676180
653ztm9yjtg31
653ztm9yjtg31
md5: 9e63803fdb219cc075c6c814521aca20🔍
>>105675868
>jinja
Replies: >>105676218
Anonymous
6/23/2025, 2:32:55 AM No.105676218
>>105676180
it's not jinja, but it's similar to it.
Django has it's own templating system, it's called DTL
Anonymous
6/23/2025, 2:35:06 AM No.105676231
>>105675868
>magic object variables
>code in HTML rather than HTML in code
I fucking hate hate hate Django
t. worked with Django at old job
Replies: >>105676256 >>105676260
Anonymous
6/23/2025, 2:39:58 AM No.105676256
>>105676231
when i see this shit im happy i didnt work one sole hour in an IT job
imagine learning all this spaghetti shit

when i need a db i just write one
it less work than fucking learning one
Replies: >>105676282 >>105676350
Anonymous
6/23/2025, 2:40:38 AM No.105676260
>>105676231
it's fine so far. What I hate the most is working with forms, it's still very prone to mistakes.
Other that that it's not that bad.
Anonymous
6/23/2025, 2:43:29 AM No.105676282
Screenshot from 2025-06-22 19-43-20
Screenshot from 2025-06-22 19-43-20
md5: 5bb46dee9effdfd64289a9ab623dbb97🔍
>>105676256
>when i need a db i just write one
you do not have transactions. you do not have a query planner. you do not have constraints. please, for the love of God, just use Postgres and learn fucking SQL. it's not that bad.
Replies: >>105676311 >>105676329 >>105676389
Anonymous
6/23/2025, 2:48:49 AM No.105676311
>>105676282
its extremely fucking bad
why would i bloat my head with this trash?
if you get paid, thats ok
but im not. why the fuck would i need this?
its a whole framework
its fucking bloated
and creating a db from scratch is dead fucking simple
to such an extent
i would really need constraints external to the project to use a pre made one

i also write in C, so its not like im stuck with python or some shit
i can write stuff from scratch in my lang,
and it usually is faster than the generalist solution bc im decent at it
and again
its less fucking work than *learning sql
why the hell should i bother? to minmax my brain into data retention?
Replies: >>105676325 >>105677807
Anonymous
6/23/2025, 2:51:28 AM No.105676325
carbon
carbon
md5: d043f95c7416f2b9b979e752f4729d60🔍
>>105676311
actual retard
fuck off with your dumb ass bullshit. if you do not see the value in transactions, then you have never worked with concurrent behavior in your life (multiple users interacting with data in your database, often doing conflicting things).
pic related is a transaction lib that I started work on in Rust. this is just a lib mind you, nothing even close to being joined alongside an actual DB implementation.
Replies: >>105676354
Anonymous
6/23/2025, 2:51:49 AM No.105676329
>>105676282
I got asked to implement a basic database with transactions during a 45 minute job interview. Why are you so positive than a random custom-built database wouldn't have transactions? It just makes you look incompetent if you don't have a particular reason for it.
Replies: >>105676370
Anonymous
6/23/2025, 2:54:13 AM No.105676350
>>105676256
https://www.sqlite.org/testing.html
Let us know how your custom database compares
Replies: >>105676371
Anonymous
6/23/2025, 2:54:27 AM No.105676353
SQL now and forever
perhaps one day we will have a new language worthy of succeeding it but the chosen one has yet to reveal himself
until then i will love and embrace my god-emperor of IBM overengineering

you will NEVER make me use your worthless faggot ORM
the beauty of relational algebra shines on you and you fizzle and recoil like the time vampire you are

i do NOT care about your non-relational faggotry either. YOU WILL NEVER BE A REAL DATABASE, YOU ARE A JSON FILE IN A DRESS.
Replies: >>105676384
Anonymous
6/23/2025, 2:54:41 AM No.105676354
>>105676325
>t. thinks concurrent behaviour is hard
>calls others retards
>uses rust (bc of course he does lamao)
why is it always the crabs?
Replies: >>105679823
Anonymous
6/23/2025, 2:56:19 AM No.105676370
>>105676329
tell me how you solved it.
what was the structure of your DB. just a hash map?
Anonymous
6/23/2025, 2:56:24 AM No.105676371
>>105676350
>https://www.sqlite.org/testing.html
i dot even need to click your link and i know that whatever im gonna shit out- drunk and baked
is gonna blow your bloat out of the water

are you retarded?
how could yout hink otherwise
>webshitter
ah
you never actually programmed in your life
that explains things
Anonymous
6/23/2025, 2:57:22 AM No.105676384
>>105676353
but orm is for programmers, sql is for db masters.
Programmers don't need to know every single databate syntax and optimization, that's a waste of their time. They only need to know the basic. Do you agree?
Replies: >>105676455 >>105676458 >>105680045
Anonymous
6/23/2025, 2:57:54 AM No.105676389
>>105676282
Man, he's not even using the grammar constraints lol you're wasting your time
Replies: >>105676398
Anonymous
6/23/2025, 2:59:03 AM No.105676398
>>105676389
>group cope therapy
lamao
Anonymous
6/23/2025, 3:07:04 AM No.105676455
>>105675746
90% of /g/ is filtered by SQL
>>105676384
No. SQL is the api for your db. You don't need an abstraction/api on top of an api. Just learn SQL.
Replies: >>105679784
Anonymous
6/23/2025, 3:07:28 AM No.105676458
>>105676384
it is perfectly fine to not master every RDBMS known to man. but knowing the ins and outs of the one your org actually uses will save you endless headaches and allow your app to actually make use of its features.
webshits get away with ORMs and noSQL slop because their needs are usually extremely simple
Anonymous
6/23/2025, 3:15:56 AM No.105676517
carlos-veggies
carlos-veggies
md5: 63fc19d8baf130209eb60700e896f5bd🔍
>squeal
Replies: >>105678121
Anonymous
6/23/2025, 7:11:17 AM No.105677807
>>105676311
>its extremely fucking bad
>why would i bloat my head with this trash?
Your IQ is too low to understand it.

>i also write in C
That explains it. C makes you retarded. C should not have existed.
Anonymous
6/23/2025, 8:27:30 AM No.105678121
4277006109_28190a75c9[1]
4277006109_28190a75c9[1]
md5: da73792221d3e93a9f39fcf0f2829f03🔍
>>105676517
>ess cue elle
Anonymous
6/23/2025, 8:36:27 AM No.105678169
>>105675719 (OP)
I optimize by not using ORM. Instead of doing a million of updates I do one bulk insert and one update.
Anonymous
6/23/2025, 11:45:19 AM No.105679124
GEsUkHnbEAELFlP
GEsUkHnbEAELFlP
md5: a3566aa07fa00e312614e1eb0a43fd2e🔍
How do I learn to write half-decent queries?

My employer recently gave me access to the company datamart, and I've been able to put together some useful reports/extracts, but I really have no idea what the fuck I'm doing beyond using left joins between dimension tables and fact tables (plus or minus a few inner joins to subqueries) until the data is broadly in the general shape I need it.
eg. We have this very tall table containing customer data which for some reason is uploaded by the source system as unpivoted- kind of like this:
>[NATURALKEY], [CLIENTDATACODE], [VALUE], [OBJECTID], [CREATEDWHEN], etc.
>8974617, Client_Surname_SYS, KIMBALL, 524215, 2025-02-17 16:42:57.00
>8974618, Client_Forename_SYS, Ralph, 524215, 2025-02-17 16:42:57.00
>8974619, Client_Gender_SYS, Male, 524215, 2025-02-17 16:42:57.00
>etc
>8974645, Client_Postcode_SYS, 60098, 524215, 2025-02-17 16:42:57.00
>8974646, Client_Surname_SYS, ROSS, 524216, 2025-02-18 08:23:31.00
>etc etc.
I worked out I could pivot it back into columns by using a function combo of MIN(IFF([CLIENTDATACODE]='Client_Surname_SYS', [VALUE], NULL)) AS "Client_Surname" via GROUP BY but the table is so big that the performance was shit, until I also found I could make a mini dimension table using this other function called VALUES ('Client_Surname_SYS'), ('Client_Forename_SYS'), etc. and inner join that onto the aforementioned before the GROUP BY which seemed to encourage to the query optimiser (this is referring to Snowflake VQL by the way) to throw out all the millions of rows I don't need or care about.
Probably not a great example but if you have any advice or tips/tricks I'd really appreciate it.
Replies: >>105679835
Anonymous
6/23/2025, 1:35:09 PM No.105679672
ddt dti
ddt dti
md5: 56cd04bf081fb32d1204a980bc5530cd🔍
>>105675719 (OP)
another thing I found
Anonymous
6/23/2025, 1:43:49 PM No.105679723
>>105675719 (OP)
Databases?
Anonymous
6/23/2025, 1:51:43 PM No.105679767
>>105675719 (OP)
No. I just have every user's data in their own json file. Optimization is only needed if you have hundreds of thousands of concurrent users who are constantly doing I/O onto your db.
Replies: >>105679779 >>105679850
Anonymous
6/23/2025, 1:53:18 PM No.105679779
>>105679767
Why would you wait to reach that point?
By doing it earlier you would be reducing costs
Replies: >>105679824
Anonymous
6/23/2025, 1:53:51 PM No.105679784
>>105676455
>90% of /g/ is filtered by SQL
to be fair, SQL is a shit declarative language.
where is my Datalog db?
Anonymous
6/23/2025, 1:56:38 PM No.105679795
>>105675789
I still kek how performant pagination is a dark art to this day for SQL cucks.
kv chads keep winning.
Anonymous
6/23/2025, 2:00:56 PM No.105679823
>>105676354
if you want high performance, concurrency and correctness, it's extremely hard and is still an unsolved field of trade-offs.
Anonymous
6/23/2025, 2:01:14 PM No.105679824
>>105679779
Approaching every project as if it's "the next big thing with hundreds of thousands or millions of users" is kinda retarded. It'll just lead you to making a bunch of pointless work.
The better approach is to structure your projects in a way where swapping out parts isn't a convoluted mess. For example, I can migrate my projects which use json files or sqlite into a more "enterprise" database whenever I want because my code base doesn't care what the db is.
Anonymous
6/23/2025, 2:03:07 PM No.105679835
>>105679124
ask questions. hash out something, ask the planner for the plan, tweak til it looks good. that's about all you can do.
Anonymous
6/23/2025, 2:06:07 PM No.105679850
>>105679767
I hope you mutex guard writes and fsync writes, but I still don't understand why you wouldn't just use sqlite from the start, unless you're a scripting language cuck.
Replies: >>105680009 >>105680080
Anonymous
6/23/2025, 2:29:15 PM No.105680009
>>105679850
>you're a scripting language cuck.
You're right. I use JS for everything, including backend code, because every other language is just shit.
Replies: >>105680148 >>105680365
Anonymous
6/23/2025, 2:32:29 PM No.105680021
>>105675719 (OP)
Two works
>composite
>keys
Anonymous
6/23/2025, 2:36:36 PM No.105680045
>>105676384
>but orm is for programmers, sql is for db masters.
Look at this guy and laugh
Anonymous
6/23/2025, 2:43:41 PM No.105680080
>>105679850
even if you have mutex guards, it gets all fucked when you read one value, then write another value based on the read value. in fact, the only way to solve this is to use a sorting algorithm for your locks. when you acquire a new lock, locks that are sorted before the new lock must be unlocked then relocked.
this all gets extremely fucking complicated, and you end up needing a transactions system to do things optimally.
Anonymous
6/23/2025, 2:50:50 PM No.105680148
>>105680009
honestly, have you tried Rust? it's probably the easiest to use low level language and the -sys style crates take care of building stuff like sqlite3 from source and linking it into your executable. It really just works. no OO bloat or anything either. If you dabble with windows programming too, having a proper low level language that can call WIN32 is nice.
Replies: >>105680365
Anonymous
6/23/2025, 3:01:37 PM No.105680212
>>105675719 (OP)
In my long years on IT, I came to the conclusion that the biggest performance issue (apart from shitty modelling) people have with DB is overnormalisation.
Replies: >>105680365
Anonymous
6/23/2025, 3:24:54 PM No.105680365
>>105675719 (OP)
This is basic shit that is only an issue for retards who use ORMs. If you are writing all your queries by hand or using a builder, you would never do something like this.

Database optimizations go way beyond that. To be honest, at work I was never in situation where it would matter. Simple webapps with few mbs of data and few queries per minute doesn't really have to worry about any of this. But my FOSS project attracted people with databases reaching hundreds of GBs and it was the first time I had to look through explain analyze dumps, understand how query planner works, manage caching etc. I'm still not entirely done because people keep bringing larger and larger databases.

>>105680009
Try better-sqlite3.

>>105680148
>easiest to use low level language
Take this with a grain of salt. Although it is powerful and reliable, it has very steep learning curve. Rust is to C what Typescript is to Javascript, except there is no implicitAny or other escape hatches, you have to write code that is provably correct from the start, which often requires well designed abstractions and complex types. But once you get a grasp on it, it's a really comfy development environment.

>>105680212
I never had any issues with normalization and I always try to make everything properly normalized. From my experience, performance generally suffers from lack of indexes or bad indexes and just badly written queries.
Replies: >>105680449 >>105681082
Anonymous
6/23/2025, 3:37:28 PM No.105680449
Screenshot From 2025-06-23 10-35-00
Screenshot From 2025-06-23 10-35-00
md5: 81d6af726dbe48a6a406710e35b3ed5e🔍
>>105680365
When you have a big database it becomes an issue.

BTW, next time you are deciding the tech stack, don't assume the client will not go crazy and start to record a shitload of useless data because one day a manager may build a graph to show in a pointless meeting...
Replies: >>105680496
Anonymous
6/23/2025, 3:42:23 PM No.105680493
1750484147966470
1750484147966470
md5: 6e88f6518bd7d35df904e86170547e66🔍
>>105675719 (OP)
all wrong.
Anonymous
6/23/2025, 3:42:39 PM No.105680496
>>105680449
>next time you are deciding the tech stack, don't assume the client will not go crazy
Postgresql and no retarded queries is enough for their needs. I can optimize it further if a need arise, but as long as there is no issues I have more urgent things to work on. Overengineering is an issue too.
Anonymous
6/23/2025, 3:46:23 PM No.105680532
huge_erd
huge_erd
md5: d9cf424967f33966bc7b3d00252f36b9🔍
>>105675719 (OP)
Managers go brrrrrrr
Anonymous
6/23/2025, 4:58:24 PM No.105681040
>>105675719 (OP)
Avoid this: python
Anonymous
6/23/2025, 5:04:43 PM No.105681082
>>105680365
>I never had any issues with normalization
Then you're not normalizing over 3NF which is fine, 6NF is schizo tier.
Replies: >>105681163
Anonymous
6/23/2025, 5:17:07 PM No.105681163
>>105681082
Oh yeah. I didn't even knew there were such degrees of normalization, I am a self taught.
I think I only go until 4NF
Anonymous
6/23/2025, 8:27:39 PM No.105682669
>>105675719 (OP)
You should know SQL even if you work with ORMs so there is no point having ORMs to begin with. Every ORM have different footguns, different features, lack of certain features of the DB (generic queries are meme and a mistake, different SQL servers optimize differently and query planner might be surprising at times even if you know what you are doing). The first one is obvious, but the fact that slicing the query somehow changes the generated query if it actually does it is just oscured. It is nonintuitive. How does it know to make a paging query after taking a slice from already created object? IIs that some kind of pending object that resolves when you take a slice (termination statement of some kind)? ORMs just obscure what queries are generated and it is just not worth it. You will use different languages and libraries in your work. Why bother learning intricacies of some ORM every time you work on a different stack? Literal trivia, useless knowledge.