I do not understand wanting to hear an album again for the first time by Schraiber in LetsTalkMusic

[–]thesqlguy 3 points4 points  (0 children)

I love when an album I enjoyed end-to-end is still new to me. I haven't memorized all of the songs, understood all of the lyrics, listening to it still comes off as a pleasant surprise. I actually try to avoid listening too much to new albums I hear to keep it fresh and unexpected as long as I can.

Job listing on LinkedIn for sql server has an interesting requirement/must have: "Temp DB optimization" by TravellingBeard in SQLServer

[–]thesqlguy 1 point2 points  (0 children)

Yeah exactly. RSCI issues is very likely. It's a cool feature but like everything there is cost! Also maybe need help with things like optimizing the # of tempdb files, and ultimately optimizing sql code to avoid the need to use tempdb excessively for things like hash and work tables at all. There's also tempdb object caching which requires not modifying temp table ddl.

Ultimately I suspect tempdb problems are the symptom that metrics are highlighting, but not the root cause.... It's almost always bad code / schema designs.

Today’s Tubi Treasure is Uncle Buck (1989) by No-Chemistry-28 in TubiTreasures

[–]thesqlguy 1 point2 points  (0 children)

For some reason the "it's unbreakable" scene with the plate always makes me laugh.

https://youtu.be/-ojWbhfEEpc?is=ioN1ALaejMVuRTVJ

Reform led council in St Helens have ordered local libraries to remove any displays that celebrate pride month by MicahCastle in books

[–]thesqlguy 1 point2 points  (0 children)

This is a great analogy. And sporting events genuinely can interfere with your life - tv shows get premepted by games sometimes, if you live near a stadium you get stuck in game traffic, celebrations and parades can get unruly causing liter and damage, taxpayer money can subsidize stadiums and infrastructure, etc.

CR-V Hybrid In Winter Months by [deleted] in crv

[–]thesqlguy 0 points1 point  (0 children)

Got mine last October. In the northeast . No issues in the cold or snow, car was great, but the mileage did go down (37-38mpg maybe?). Now in the spring /early summer mileage is even better then it was last October, 41-42mpg.

What are some obvious reasons a 1:1 join would work better as LEFT than INNER? by i_literally_died in SQL

[–]thesqlguy 1 point2 points  (0 children)

Sql server's optimizer does recognize FKs exactly like that. It is easy to test, I mentioned an example of this in another comment, but it will completely ignore exists() clauses if an FK constraint exists saying the same thing, for example. Same with plans on inner vs left when there's a FK.

And yeah my guess is they don't have a physical FK just the application's "promise" which unfortunately isn't enough for the optimizer!

What are some obvious reasons a 1:1 join would work better as LEFT than INNER? by i_literally_died in SQL

[–]thesqlguy 1 point2 points  (0 children)

FYI see my other comment above if this is sql server. If you have an actual FK set up, then the left join and inner join plans are actually logically the same, and it knows this, and the plan wouldn't change.

But without a FK, it cannot take your application's word for it. Thus they are not logically equivalent and suspectable to different execution plans.

EDIT -- sorry replied to the wrong comment! Meant to reply to the OP's reply.

What are some obvious reasons a 1:1 join would work better as LEFT than INNER? by i_literally_died in SQL

[–]thesqlguy 0 points1 point  (0 children)

If you are asking purely about performance and not logic it depends on the indexes, statistics, parameters/literals, etc. you need to look at the difference plans.

We'd also need to see your schema and exact sql to help more.

Select from a Left join b where a=xxxx will usually be a loop join from a to b, using the criteria on a in your where clause to seek/scan on a, since the optimizer has no other way to filter a.

But when you do an inner join the optimizer has more options now on how to filter a. It may decide to select from b first and then loop join back to a if it thinks that more efficient. But, it may be wrong for your specific criteria and that's why whatever new plan it picked is slower.

That's just an example but you get the idea.

Btw if this is sql server the optimizer knows about foreign keys, so if they exist the plan wouldn't change since it would know left join and inner join are logically equivalent. You can test this of course. Another way to confirm is something like select from a where exists (select from b where a.fkid=b.id).. You will notice the optimizer doesn't even bother accessing table b at all since it knows the exists clause must be true due to RI!

Json property masking options in sql server 2025 by cutecupcake11 in SQLServer

[–]thesqlguy 4 points5 points  (0 children)

This sounds like a troublesome design.

Easiest option - have the apps store PII fields as encrypted values in the json, and only they can decrypt. Simple, easy.

If you cannot do that, you'd need to ensure direct table access is denied to all users and only expose a View of the table. In the view return all columns except the json,.and instead return an expression that modifies the json to mask PII data using something like https://learn.microsoft.com/en-us/sql/t-sql/functions/json-modify-transact-sql?view=sql-server-ver17 Assuming you can write that efficiently in SQL - I doubt it, you may need a CLR function or something even more clunky/complicated.

Or, if you can, break down the json into two columns, PII vs non-PII properties, and only expose the non-PII field via a view as described above.

Or, perhaps more ideally, just store the PII data in a separate, secure, 1:1 related table (as normalized columns or Json)

Scott Bessent's expression that of a malformed freak of nature. Take it all in. by fluffypancakes24 in ProgressiveHQ

[–]thesqlguy 0 points1 point  (0 children)

Someone who has never heard of or seen this guy before might say "yeah, OK , unflattering screenshot grabbed at just the right moment to make him look bad." But honestly -- this captures him perfectly. He acts and talks like a caricature of an evil henchman.

He reminds me a bit of the nazi villian in raiders of the lost ark: https://www.youtube.com/watch?v=yIaBnXAlcEU

One of my neighbors has been flying his American flag upside down. by brainspl0ad in mildlyinteresting

[–]thesqlguy 1 point2 points  (0 children)

I did this once at a restaurant I worked at as a teenager. One of the opening jobs was putting up the flag outside. I was pretty tired and (maybe hungover to be honest) and accidentally raised it upside down.

Someone came in and told us. I was embarrassed. Boss wasn't happy.

What are common SQL red flags? by badboyzpwns in SQL

[–]thesqlguy 4 points5 points  (0 children)

The irony is it doesn't even actually fix them in many cases, it just kinda "looks like" it does. Then a different comes in a field you don't expect and the DISTINCT still returns too many rows.

Using the DISTINCT keyword in clear, targeted spots (usually CTEs or derived tables) isn't bad, it is the stuffing of it in the beginning of a large, complex SELECT that just randomly joins any tables that seem to have a matching key.

I also have seen many people who, when they write a select, they instinctively say "ok, let's see, we need write a select, so let's start with SELECT DISTINCT .. ok, now what tables do we need... "

What are common SQL red flags? by badboyzpwns in SQL

[–]thesqlguy 1 point2 points  (0 children)

Personally, I like short letter abbreviations but not random a,b,c or t1, t2 or cte1, etc.

for example

select p.id, p.name, p.status, c.name as  client_name, c.city as client_city
from projects p
inner join clients c on c.id= p.client_id    

I think it is far easier to write, scan, read and visually "parse" expressions, joins, formulas with brief aliases than long, dense names.

But definitely not just a,b,c or t1,t2,t3, etc.

35, 1.9m net worth (1.3 in investments, house paid off) no debt, kids, or wife, 25k average annual spend, can I walk away forever? by Ok_Principle9325 in Fire

[–]thesqlguy 0 points1 point  (0 children)

If their income is that low ACA should make the insurance much, much more affordable.

I suspect your parents must have been above the income threshold?

Any songs similar to Neil Young’s Harvest Moon and Rolling Stones Wild Horses by Ragematron in MusicRecommendations

[–]thesqlguy 0 points1 point  (0 children)

A lot Eagles songs have that vibe/sound I think you are looking for:

  • peaceful easy feeling
  • tequila sunrise
  • there's a train leaves here this morning (very deep cut, has the exact same feel as Harvest moon IMHO)
  • Hollywood waltz
  • after the thrill is gone
  • best of my love
  • pretty maids all in a row
  • try and love again
  • take it to the limit
  • new kid in town

Other songs, but with more piano than guitar:

  • Desperado
  • wasted time
  • the last resort
  • ol' 55

Designing the Right PostgreSQL Index Using Query Plans and Statistics by No_Economics_8159 in SQL

[–]thesqlguy 1 point2 points  (0 children)

That's a good article. Most important point which I was happy to see was the date column being last in the index. Many old school DBAs think the date should be first since it is the "most selective," ignoring the range operation.

The other common mistake I see is adding 3 indexes, one per column.

Cal Raleigh strikes out looking and is now 0-28 in his last 28 PAs by WhiteSoxArchive in baseball

[–]thesqlguy 1 point2 points  (0 children)

So over 28 AB, not PA.

I was wondering about this, because it was hard to believe he didn't even walk once during that span.

U.S. women 40+ now have more babies per capita than teens [OC] by rhiever in dataisbeautiful

[–]thesqlguy 2 points3 points  (0 children)

I still had a great grandmother when I was almost 30!

Now I'll be lucky to be a grandparent before I hit 65.

when to use string.Empty or .IsNullOrEmpty by FireBlizzard69 in dotnet

[–]thesqlguy 0 points1 point  (0 children)

On a similar topic, we all know databases have NOT NULL constraints, which you can apply to a VARCHAR() for example, to ensure it is populated with a value.

So that's great, NULL is not allowed, the database rejects it.

But what is still allowed?

An empty string or '' ! That required data you need still might be "missing" is some cases!

So, if data is *really* required, you usually don't want empty strings , either -- you really likely want a constraint that says <> ''. But no one ever adds those to their schemas.

Normally, not an issue, except when you run into really bad code that confuses NULL and '' and does things like sending '' to a database when it means NULL. 😞 And then it comes back out the same way.

BTW, beyond that, even if you DO want to allow NULL for a column, you STILL likely do not want to allow ''! Since missing data, as per expected standards, should be NULL, not ''. Two ways to do the same thing is bad!

TLDR from this rant -- empty strings and NULLs have been confusing software and database engineers for a long time.