News for hackers. Stuff that matters.
Re:Ideas to improve the user and developer experiences of da... by willvarfar on Wednesday March 10, 2021 @04:01AM (#26409302)
The main thrust seems to be tooling in the db to give developers some idea of the performance impact of the code they write.

But most programmers are using frameworks and ORMs and things that hide away what is actually happening with the database. A normal developer can look at a chunk of code on their side and have no real idea of what is happening on the database behind them.

What webdevelopers need is backend profiling information e.g. actual SQL queries and timings, shown beside all the frontend profiling information (e.g. in webdeveloper tools in the browser).

This profiling introspection can come from tooling in front of the database(s).

I recall seeing a blog about how the Stackoverflow team have nice tooling that does this for them. (Impossible to google for words like "stackoverflow profiling" and things!)

Re:Ideas to improve the user and developer experiences of da... by tpetry on Wednesday March 10, 2021 @06:12AM (#26410065)
You could easily instruct the orm to add a comment in front of the sql query so the database can profiling of a complete http request and show you all the bad things your orm is doing.

Something like: /* dbxperience:request=9a7cd2a6 */ SELECT ....

I have not tested it, but this is something google cloud sql recently promoted: https://cloud.google.com/blog/products/databases/get-ahead-o...

Re:Ideas to improve the user and developer experiences of da... by theptip on Wednesday March 10, 2021 @11:32AM (#26413000)
You don’t need to go this path; modern(-ish) APM systems like Datadog will let you trace SQL commands in the context of the request being made. You can group by endpoint, or group by sql (merging IDs that differ), or chop and filter the data however you need. The DB is not in a position to give you all the stats you need; instead the DB should support e.g. exporting plan info to further enrich the whole-request metrics that are already being collected.

I use this in prod; it’s great. Expensive though.

https://www.datadoghq.com/blog/mysql-monitoring-with-datadog...

Re:Ideas to improve the user and developer experiences of da... by sa46 on Wednesday March 10, 2021 @02:34PM (#26415173)
I've used Datadog but if you need per query tracing from the database logs, I think the only way is to embed a trace ID in a SQL comment (or in an no-op column) like the grandparent showed.

Datadog is tracing the request from the application akin to something like

    openTrace("Query Name", queryStr)
    db.Query(queryStr)
    closeTrace()
The gap with that style of application-level tracing is that the database logs give no indication of where a query came from, hence the need for embedding a comment in the query with the trace ID.

I would love for a better mechanism than SQL comments for distributed tracing all the way to the database.

Re:Ideas to improve the user and developer experiences of da... by theptip on Wednesday March 10, 2021 @03:38PM (#26415890)
I guess what I'm getting at is questioning why you need to look at the database logs (beyond what your APM system can pull from the DB's metrics).

What are you getting from the DB logs that you can't get elsewhere?

Re:Ideas to improve the user and developer experiences of da... by sa46 on Wednesday March 10, 2021 @10:31PM (#26419866)
Sure, off the top of my head:

- Explain plans for slow queries, via auto_explain in Postgres. You could get really fancy here and convert the pieces of an explain plan (Aggregate, ModifyTable, FullTableScan) into proper distributed traces. Hard to tell, but it looks like GCP might offer that.

- Various errors logs associated with queries that require more detail than a SQL state code. For example, lock timeouts.

- Debugging, especially root cause analysis when you're trying to figure out why something broke. The trace IDs help build up context.

Re:Ideas to improve the user and developer experiences of da... by planxty on Wednesday March 10, 2021 @08:45AM (#26411110)
"Easily", not sure that is always easy to do. Is a clever approach to be sure, but to the author's point there could probably be better UX.
Re:Ideas to improve the user and developer experiences of da... by dntrkv on Wednesday March 10, 2021 @11:42AM (#26413130)
Apollo's GraphQL server has a VSCode plugin that shows you the average response time of a query. This type of tooling is difficult to implement but I think can be super useful.

https://marketplace.visualstudio.com/items?itemName=apollogr...

Re:Ideas to improve the user and developer experiences of da... by sbelskie on Wednesday March 10, 2021 @09:16AM (#26411418)
Re: Stackoverflow and showing profiling information on the front end, you are likely talking about Miniprofiler.

https://github.com/MiniProfiler/dotnet

Re:Ideas to improve the user and developer experiences of da... by avereveard on Wednesday March 10, 2021 @05:23AM (#26409781)
what we need is to kill ORM stile framework (think hybernate) and move the world toward mapper style frameworks (think mybatis)

sure, inserts are slightly more inconvenient. but the clarity and performance control on reads unparalleled.