Readit News logoReadit News
funnymony commented on Don't use DISTINCT as a "join-fixer"   red-gate.com/simple-talk/... · Posted by u/todsacerdoti
munch117 · 2 years ago
> If distinct is used in any of above, then question “why?” naturally arises.

Not if distinct is the default.

> Select distinct student.student_name, parent.parent_name from student join parent on student.parent_id = parent.parent_id —- silently discards rows, where by accident student/parent name combo matches several times.

Either with or without distinct can be a bug depending on what you are doing it for.

There are actually 4 variations on what you might want, and you can get all of them with distinct:

  select distinct student.student_id, student.student_name, parent.parent_id, parent.parent_name from ...
  select distinct student.student_name, parent.parent_id parent.parent_name from ...
  select distinct student.student_id, student.student_name, parent.parent_name from ...
  select distinct student.student_name, parent.parent_name from ...

funnymony · 2 years ago
These examples reminded me one more issue: change in column selection, might change number of rows, which means column addition/removal is so much riskier afair.

> Not if distinct is the default.

If that works for you, great, but let’s agree to disagree here.

funnymony commented on Don't use DISTINCT as a "join-fixer"   red-gate.com/simple-talk/... · Posted by u/todsacerdoti
gigatexal · 2 years ago
You mean the where exists/not exists concept? Or the select 1 usage in that correlated subquery?
funnymony · 2 years ago
1
funnymony commented on Don't use DISTINCT as a "join-fixer"   red-gate.com/simple-talk/... · Posted by u/todsacerdoti
munch117 · 2 years ago
I don't. I put distinct on everything by default, because it makes SQL more like relational algebra.

What's the argument for avoiding distinct? Is it performance? I've often wondered if the (sometimes redundant) distincts slow things down. Perhaps it does, but just not enough that I noticed.

funnymony · 2 years ago
Performance implication exist, but it is secondary.

Primary reason: distinct on every select shows either lack of knowledge of schema, in particular which columns make rows unique, or unfortunate schema design. (Apart from niche cases, schema should be somewhat normal. I.e. column parent_name belongs in the table parent, not in the table student)

Select a from x where myuniquekey=1; —- guaranted to return 1 or zero rows, if myuiniquekey is actually unique.

Select a from x join y on x.parent_id = y.y_id —- guaranteed to return same amount of rows as exist in y, never more, never duplicates y rows. (N-to-1 relation)

If distinct is used in any of above, then question “why?” naturally arises.

In more severe case, leads to bugs:

Select distinct student.student_name, parent.parent_name from student join parent on student.parent_id = parent.parent_id —- silently discards rows, where by accident student/parent name combo matches several times.

Technically sql allows comparing unrelated columns (colour=last_name), but for vast majority of cases, when joining, one of the side should be joined using it’s unique key, and other side should be using it’s foreign key, which ensures that duplicates don’t appear randomly, and thus distinct is not needed.

funnymony commented on Don't use DISTINCT as a "join-fixer"   red-gate.com/simple-talk/... · Posted by u/todsacerdoti
gigatexal · 2 years ago
This isn’t readable? It’s a common pattern.
funnymony · 2 years ago
Its a matter of your eyes being used to this.

If for ten years you always indented the code this way

    Void F()
    {    Foo();
         Bar();
         Baz();}
Then following snippet will seem hard to parse mentally:

    Void F()
    {
         Foo();
         Bar();
         Baz();
    }
And vice versa

funnymony commented on Sweden reports damage to Baltic Sea cable with Estonia   dw.com/en/sweden-reports-... · Posted by u/perihelions
funnymony · 2 years ago
Somewhat relevant. Estonia has a law that financial instutions should have servers located on Estonian soil. (Exactly for this kind of scenario)
funnymony commented on Escape analysis hates copy elision (2021)   quuxplusone.github.io/blo... · Posted by u/pornel
MaxBarraclough · 2 years ago
I'm afraid I don't know about Rust, but D has the scope parameter storage class for this. It enables the following compiler-enforced guarantee:

> The parameter must not escape the function call (e.g. by being assigned to a global variable). Ignored for any parameter that is not a reference type.

https://dlang.org/spec/function.html#scope-parameters

See also: https://dlang.org/blog/2023/10/02/crafting-self-evident-code... , https://news.ycombinator.com/item?id=37748543

funnymony commented on John Carmack and Rich Sutton partner to accelerate development of AGI   amii.ca/latest-from-amii/... · Posted by u/hardmaru
danielbarla · 2 years ago
> They discovered the immobilised kitten's visual processing did not develop normally whereas the mobile kitten's did, suggesting that it's not just the sensory input, but it being feedback to some internal agency within the brain.

> I suspect the same thing would be true for attempts to develop AGI...

On the other hand, I would not be surprised if this did _not_ generalize and translate to LLMs. Biological entities on earth tend to have tons of fairly arbitrary developmental legacy which may or may not translate well to an artificial one. In the experiment, they didn't make billions of clones of the cat with a variety of different parameters and check which one worked, they just observed that yes, this standard v1 cat has some specific hard-wired developmental tendencies. It is not surprising that taking it out of the environment it was evolved for messes things up, but I would not take the extra step that this means that something is essential in general.

funnymony · 2 years ago
This would be like learning everything from books vs learning by experience. (Can’t learn skiing from books. I talk from experience)
funnymony commented on Strong static typing, a hill I'm willing to die on   svix.com/blog/strong-typi... · Posted by u/tasn
tasn · 2 years ago
Author here. One thing that we do at Svix that I alluded to in one paragraph but I should probably have elaborated on further: thanks to libraries like Serde and Pydantic, we actually follow deserialization is validation (is that a term?), which means that we validate all of the JSON data before even creating the structures in our code.

I guess that's similar to the redis example I gave, but it essentially means that even though we get sent JSON over the wire, we validate it fully and when it gets to our code we know it's a well formatted type. So our code can assume an email type is a valid email, an ID type is a valid ID, etc.

funnymony · 2 years ago
> deserialization is validation

I saw similar, catchy phrase: “parse, don’t validate”.

https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...

funnymony commented on Modern genetic data suggests pre-humans were a group of only 1,280 individuals   nature.com/articles/d4158... · Posted by u/geox
somenameforme · 2 years ago
Killing was an extremely very poor choice of words on my part, as this certainly doesn't have to involve death. Take South Korea as a contemporary example with their publicized 0.7 fertility rate. That trends towards extinction at an exponential pace. But now imagine there was another group within South Korea that started going the opposite direction and just having massive numbers of children.

You could even create an equilibrium level (probably more theoretic than practical at the population levels in modern times, but not necessarily in ancient) where this group's fertility trends up end perfectly balancing against the rest of South Korea's low fertility trends, such that the population doesn't even meaningfully change, or maybe even increases, yet the DNA pool ends up near to 100% controlled by a tiny minority. I'm curious if and how this would look different (from a long distant DNA analysis) from the suggestion that suddenly all of South Korea just mysteriously died and these were the only people left.

funnymony · 2 years ago
Interesting idea. But this would require no intermixing between groups.
funnymony commented on How to Roman Republic 101, Part IIIb: Imperium   acoup.blog/2023/08/18/col... · Posted by u/Khaine
1letterunixname · 2 years ago
George Carlin would agree. Fewer idiots electing fewer charismatic despots would be a good start.

Also, I don't vote so the politicians are the responsibility of people who mistakenly believe their vote matters when they are selectively stolen, gerrymandered, and manufactured consent into futility. 45 may have tried to steal Georgia like a moron, but Bernie lost the 2016 WV primary even though every district voted for him as the consequence of that state's electors collusion with one candidate. Until there's sortition, campaign finance reform, or an emperor, NPVIC could eventually be a potential workaround for electoral mutinies.

Until then, there's not much chance of change because the only viable candidates are celebrities and career politicians willing to bend the knee to big money donors in exchange for favor$.

funnymony · 2 years ago
Problem is that despots want power, whatever system you have you will get despots wanting to be at the top, and doing what is necessary to get there. Democracy at least moves them around a bit.

u/funnymony

KarmaCake day96October 8, 2022View Original