17

Imagine a junior database developer / DBA that may not have an avenue to get their SQL code reviewed for best practices and such as they are learning the ropes. There is of course the Code Review Stack Exchange (CR.SE) site, which can and will review SQL if it is posted and falls within the site guidelines.

However, there are a few concerns in that regards. The primary one IMO is:

Real DB objects vs. hypothetical ones

CR.SE questions must include real code that OP owns or maintains; this can present a challenge as a good portion of SQL code is often DB object names, which can present security or regulation repercussions to the OP for revealing those.

There is as a workaround the option to rename the DB objects to something more generic, which will preserve the logic of the code while removing potentially sensitive information. This, however, on CR.SE would likely get closed as "hypothetical code" if the reviewers saw things like

SELECT foo
FROM table1 AS "orders" 
JOIN table2 AS "customers"
  ON "orders".cust_id = "customers".id

There is also the less problematic, but still meaningful difference that many regulars on DBA.SE appear to be database professionals, rather than "programming professionals who know SQL", which might provide more valuable information to the OP's benefit (and that of potential future viewers), but the fact that there would not be a problem statement or specific question per-se related to databases might not be that well-received on DBA.SE?

--

All constructive opinions appreciated!

2 Answers 2

6

Summary

  • Good questions that will benefit from 'pro-level' review are on-topic here.
  • If only a basic review is required, migrate to Code Review if it is on-topic there.
  • Do not migrate crap questions to any SE site, ever.
  • The question of "real or hypothetical" objects does not affect topicality here.
  • Very basic questions are generally off-topic here, whether 'code review' or not.

More Detail

Having thought about this for a while, I'm not sure very much has fundamentally changed since Jeff Atwood answered Overlap between codereview and dba back in 2011:

I think it depends if you need a "pro" level review or just basics.

  • If it's just the basics and you have limited database experience (and there's nothing wrong with the basics) then a generic code review is fine.

  • If it's a complex schema and you have lots of database experience, then asking here is preferred.

Remember, the audience is professional DBAs on this site -- database specialists. If your question is more basic and general, it belongs on Stack Overflow or Code Review, where there are more generalists.

The second answer on the same post has a fine diagram by jcolebrand:

enter image description here

To address the specifics in this new question:

  • If the question meets our normal quality requirements, it does not matter if the example is 'real' or 'hypothetical'. A 'pro level review' based on an abstraction or simplification of the real problem seems perfectly possible to me, so long as the example captures the essence of the problem.
  • More 'basic' questions are probably off-topic at present. This is less about the "code-review" style than it is about (otherwise good but) basic questions in general. We do revisit this from time to time.
4

To be honest, most folks here are going to want a working testable query in the first place. Can you not rename the table to something more coherent and then create a http://sqlfiddle.com/ for the environment, and link to that. This lets you build out mock schemas and dummy data to prove the query.

Honestly tho, sometimes the answer is "rewrite the query". When you do that, bugs go away. If you can't get rid of the bug that way, keep reducing till you get to the root of the problem. Then you can put THAT on a sqlfiddle and ask on CR or here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .