« first day (2237 days earlier)      last day (2624 days later) » 

1:21 AM
@MaxVernon Change the format of the cells to text data type first
 
 
11 hours later…
11:55 AM
What happened to this meta q exactly?
-3
Q: Is there any way to fix reputation mechanics here?

Matthew SontumI have only tried answering questions here for a few days. But I am troubled by the mechanics of the site. So far I've answered 36 questions. Of those 2 were accepted as the correct answer, 7 have received up-votes but were not accepted as the correct answer, 23 have received no votes and 4 have ...

It was moved to meta.se, got 2 more answers there, then it got closed as of-topic there, so the migration should have been rejected and the q moved back here, automatically.
Unless these migrations work differently.
Now the question appears to have been split in 2, the one in our meta has Brent's answer and the one at meta.se has the other 2 answers.
Any @mod care to explain this?
Is it related to the user being banned?
 
12:08 PM
I think the question was never locked since the rejection, while the ban came substantially later (something like 1 or 2 hours later).
Not 100% sure about "never" but at least it wasn't locked when I looked at it soon after it was rejected.
 
And when did the split happen? When the migrated reached 5 votes and got rejected?
Because we could see Brent's answer in meta.se before.
 
12:29 PM
Where do I sign up?
 
12:40 PM
Monitoring various performances? I wonder who the performers are.
@ypercubeᵀᴹ Not sure what you mean. Brent answered while the question was here. I don't know if the answer was deleted after the migration but if it was, apparently it was undeleted after the rejection.
 
@AndriyM when the question was migrated at meta.se, Brent's answer was there, too.
Then I added my answer there
The question was visible at Meta.SE with 3 answers, until it was closed there.
 
@ypercubeᵀᴹ Migration technically means copying. The question was copied to the other site along with the answer and all the comments. I think answers are deleted at that point but I'm not sure. If they are, they are soft-deleted anyway.
 
@AndriyM That (copying) makes some sense then.
When the q was migrated, the existing answer was copied, too.
The q also stayed here (and was showing as migrated, now is still shown as closed)
Still it only makes some sense. Not much sense.
 
12:55 PM
@ypercubeᵀᴹ Yes, that's what I remember happening in other cases. If I had an answer on a migrated question, I would expect to lose the associated rep on the originating site. And if the question was migrated on the target, I'd expect the rep to be restored. At least if I cared that much, I mean. And that's what I think the devs might think an answerer to expect.
 
It confirms @PaulWite's thoughts'
Mar 21 '16 at 8:39, by Paul White
There's nothing good about a rejected migration.
@AndriyM I don't care about the rep. My main concern is: why were the answers not copied back to our meta, when the migration was rejected?
And why does the q still appears on meta.se?
> put on hold as off-topic by Patrick Hofman, ale, Cai, jcolebrand, Nathan Tuggy yesterday

> This question appears to be off-topic. The users who voted to close gave this specific reason:

> "This question pertains only to a specific site in the Stack Exchange Network. Questions on Meta Stack Exchange should pertain to our network or software that drives it as a whole, within the guidelines defined in the help center. You should ask this question on the meta site where your concern originated." – Patrick Hofman, ale, Cai, Nathan Tuggy
 
@ConcernedOfTunbridgeWells So your body clock's pre-adjusted for the move. Handy.
 
@ypercubeᵀᴹ Not sure but I think answers added on the target site are usually not migrated to the site of origin after the rejection. I made a mistake in my last comment, by the way: I said "if the question was migrated on the target" when I actually meant "if the question was rejected on the target", sorry, that might have added some amount of confusion.
 
@ypercubeᵀᴹ As it happens, around here that's for the emergency services.
 
Although even if I said what I meant, the matter would still remain a bit of a mystery (to me at least). As far as I remember, rejected questions usually end up locked on the original site, and that didn't happen here.
 
1:09 PM
@MichaelGreen interesting. Where's that, USA?
 
@MaxVernon Fun fact: letters to Santa get their own postal code - H0H 0H0
@ypercubeᵀᴹ Australia.
 
2:05 PM
@ypercubeᵀᴹ Always makes a mess. I'll make some enquiries to see if it can be fixed up.
Unrelated:
158
Q: Comprehensive question quality blocks now enabled everywhere

Shog9Questions are the lifeblood of any Stack Exchange site. But asking good questions can be difficult, and while most people start off doing it poorly, some never get better. For years now, when sites reached traffic levels that made manual review and filtering of questions burdensome for the good f...

 
Brent's answer was deleted here at initial migration time, when all of the content here was copied (and locked, IIRC). When the migration was rejected, the question here was unlocked but still on hold? Brent's answer stayed deleted.
I'm sorry I caused a mess. Since it seemed to be a wholly uninformed critique of how all of the sites work, I thought it would be useful to expose his question to all of meta.
 
@AaronBertrand Yeah rejected migrations are a bummer. You did the right thing in my view. I've asked for the migration to be reversed.
The final state will be OK it just might take a few hours to get there.
We can reopen the question on meta.dba now though.
Sad that rejected migrations don't do that automatically, but don't get me started.
 
Since he used an example from dba.se, the meta zealots didn't like it. But his primary concerns are applicable to any site in the network, and explanations of why it works this way will be better if they come from a bigger, broader audience.
Though now I think we're in for a long road with this fellow.
 
We'll see, in 8 hours or so.
I guess you guys can't say but the suspension was due to the hacking threats.
 
2:21 PM
@AaronBertrand That's meta.se for you, as you said a few days ago I think. It belongs there but hey if they don't want it, OK.
@ypercubeᵀᴹ "This account is temporarily suspended for rule violations. The suspension period ends in 8 hours."
:)
 
 
2 hours later…
4:39 PM
28
Q: Biker purist required to travel for work

guest posterThere is an employee at my organization that is 100% pro bike and 100% anti-combustion engine. He is very vocal about it, and everyone, including myself is generally supportive of his choices and knows him as that dedicated life choice kind of guy. Most days, he bikes to work as you would expect....

 
does that guy never go on vacation?
 
@JoeObbish He goes on his bike.
I wonder, does he use electricity?
The electricity all over the world is mainly produced from non friendly to environment methods
@ypercubeᵀᴹ I tried but wasn't able to, may be the mobile app not letting me. — MguerraTorres 2 mins ago
She wants to delete her answer, mobile app isn't functioning.
 
4:56 PM
@ypercubeᵀᴹ Not quite the same thing, perhaps. His bike or some of its components may have been produced by environment-unfriendly methods, which doesn't make him avoid using it.
 
5:07 PM
Hi guys
Just a quick question, I made a table (Matrix) and noticed the sequence of the Product ID is randomised. Hence I used the tablix properties to sort by the Product ID but this is not working?
 
Matrix? tablix? What are those?
 
How are you determining that the sequence is "randomized"? Are you selecting from the table without an order by?
 
@AndriyM SSRS Sorry!
:35525743  SELECT NON EMPTY { [Measures].[Cost Sales], [Measures].[Margin], [Measures].[Quantity Ordered] } ON COLUMNS, NON EMPTY { ([Product].[Products].[Discontinued].ALLMEMBERS * [Time].[CalendarSales].[Month].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM [NorthWindDW_SSAS] CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
@AaronBertrand You can view the query below the query run against the cube
 
Urgh, square brackets
 
@Philᵀᴹ Tell me about it
@AndriyM Have you used Sql analysis tools?
 
5:20 PM
Ok so like this
1
Q: SSAS / MDX Query - Sort a CellSet

CallumVassI have an MDX query where I am returning a list of products and the total sales value for that item from my SSAS cube, like so: SELECT NON EMPTY { [Item].Children } ON COLUMNS, { [Total Line Value] } ON ROWS FROM [Sales Analysis] What I would like to do is sort the results in ...

I just searched for "sort mdx on columns"
 
@AaronBertrand Would it be easy if I can customise the ProductID by creating an expression
 
@Dodi82 I haven't. I'm a bit curious about MDX but so far my attempts at making sense of it have been unsuccessful.
 
@AndriyM Just give it a try! You may like it
 
I have no idea, sorry. You wanted to know how to sort, I found an answer that shows how to sort.
 
@AaronBertrand Thank you muchly
 
5:25 PM
And yes, still learning the mobile app, just realized there is a way to reply directly
 
@AaronBertrand Good luck I am the same here still learning :)
 
6:01 PM
any SQL Server folks still around? have a bit of an odd question
 
@JoeObbish "SQL Server folks" is a rather broad term. I consider myself one of them but I'm a developer and specialise mainly in T-SQL questions.
 
@AndriyM fair point. this is a T-SQL/query optimization question
 
@JoeObbish If it's not already posted somewhere, go ahead and ask (here). We'll also see if it's worth actually posting.
 
@AndriyM Sure, although I'm not asking on the main site because I think it would be closed as "too localized"
simple table definition: CREATE TABLE X_LARGE_TABLE (UNIQUE_KEY INT IDENTITY(1,1), ID VARCHAR(100) NOT NULL);
about 30M rows in the table
ID is highly skewed
only 3 distinct values
I want a query that is equivalent to the following to return as high of an estimated number of rows as possible: SELECT DISTINCT ID FROM X_LARGE_TABLE
so SQL Server thinks there will be 2 rows returned
I want it to be 30 M or close to that
I don't want to join to another table
don't want to use the UNIQUE_KEY column if possible (I already have a solution that does that)
not sure if that makes sense
 
@JoeObbish why should it be 30M?
You said it has 3 distinct values
 
6:12 PM
My question exactly
 
@ypercubeᵀᴹ I want to trick the optimizer
I can get into the "why" if you guys want
 
Hm. Maybe try a hash function on ID?
 
which function? I haven't had luck with any that I've tried so far
 
or add a random value?
ID is varchar , right?
 
yeah
random value didn't work when I tried it
but I could have used the wrong function
 
6:15 PM
Not a hash function but throwing NEWID() into the query might change the estimate, although if you still want the result to have three rows, I don't know.
 
ID + CAST(NEWID() AS VARCHAR(40)) or something
 
tried that already
 
Yes, do you want the result to be still be 3 rows?
 
SELECT DISTINCT CONVERT(varchar(255), NEWID())
FROM X_LARGE_TABLE
has an estimate of 1
there might be a form in which it works
yeah, I want the results to be the same
let me go over something that works
which I would prefer not to do
 
I'm not sure, perhaps use RAND instead of NEWID.
 
6:18 PM
SELECT DISTINCT ID + SUBSTRING(CAST(UNIQUE_KEY AS VARCHAR(100)), 98, 100)
FROM X_LARGE_TABLE
OPTION (MAXDOP 1)
 
I guess that wouldn't work either
 
that one has an estimate of 28803800 rows
UNIQUE_KEY will always be less than 98 characters as a VARCHAR
so substring returns an empty string
but uses the UNIQUE_KEY column
so the question is, is there any expression on just ID which accomplishes the same thing?
 
Yes, I can see how this could be closed as too localised if asked without an explanation why you want to do this and avoid what you said you want to avoid. Do you think your explanation could make it look less localised?
 
SELECT DISTINCT ID + SUBSTRING(' '+CAST(NEWID() AS VARCHAR(40)), 2, 1)
 
@ypercubeᵀᴹ estimated rows is 2
@AndriyM Not sure. I'll go through it here
I'm trying to effectively force SQL Server to use hash match (flow distinct) to find the distinct values
but there doesn't appear to be a way to get that through optimizer rules
so the idea is that if I inflate the estimated number of distinct values then the query optimizer will pick that operator
instead of doing a blocking hash match
 
6:23 PM
SELECT DISTINCT ID FROM (SELECT DISTINCT ID, NEWID() FROM X_LARGE_TABLE) AS s (or maybe without the inner DISTINCT)?
 
essentially I want SELECT DISTINCT TOP 2 ID FROM X_LARGE_TABLE to use hash match (flow distinct)
@AndriyM that one doesn't work either
 
This may be my ignorance speaking but I still don't understand why, for instance, using UNIQUE_KEY must be avoided.
or "should preferably be avoided".
 
SELECT ID
FROM (SELECT TOP 3 DISTINCT ID, n =  NEWID() FROM X_LARGE_TABLE ORDER BY n)
 
@ypercubeᵀᴹ 1 row
@AndriyM No, that's definitely a fair question. This is just an academic exercise at this point.
However, I think I have a way to phrase the problem so that it's not too localized
as I can come up with an example data set for which the optimizer gets it wrong
and for which hash match (flow distinct) is much faster
so it seems fair to ask how to optimize that query
@ypercubeᵀᴹ derived table has an estimate of 2
 
Yeah. I guess a TOP 3 could never have an estimate of millions. Silly cube
 
6:33 PM
removing top 3 doesn't help
also it could if you used OPTIMIZE FOR
would this be on topic?
test data:
CREATE TABLE X_LARGE_TABLE_2 (ID VARCHAR(100) NOT NULL);

INSERT INTO X_LARGE_TABLE_2 WITH (TABLOCK)
SELECT CASE WHEN N % 2 = 0 THEN 'A' ELSE 'B' END
FROM dbo.GetNums(30000000);
the following query scans all rows from the table:
SELECT DISTINCT TOP 2 ID
FROM X_LARGE_TABLE_2;
I want an equivalent query that does not
the first data page in the table has 2 distinct values, so it seems inefficient to scan the entire table
 
@JoeObbish doesn't it stop when it finds the first 2 distinct values?
 
@ypercubeᵀᴹ Nope, that's the problem
I get hash match (aggregate) which is blocking
I want hash match (flow distinct) because that is a streaming operator
that one stops after the first 2 distinct values
 
If you change the DISTINCT to GROUP BY, does it have the same plan?
Still, it's weird, I don't know.
 
same plan
 
Looks like a question for the site.
 
6:43 PM
The example doesn't look to me too forced. I'd certainly be interested to know the answer to that question.
 
I'll write it up on Monday
thanks for looking at this, I appreciate it
 
A recursive CTE would surely avoid the issue ;)
 
huh... I think it actually would
although, if it's a heap
if the data isn't that tightly packed you could run into an issue, right?
 
If all the A values are found before a single B, You'd have to read half the table. Heap or CI, I don't see any difference.
What about a subquery with a window function and rnk <= 2?
I wonder if that would work.
The CTE would not be hard to write for TOP 2. But for anything higher, it will be a pain.
SELECT id
FROM
  ( SELECT id, rnk = RANK() OVER (ORDER BY NULL)
    FROM x_large_table_2
  ) AS x
WHERE rnk <= 2 ;
Nah, disregard
Maybe this:
SELECT id
FROM
  ( SELECT id, rnk = ROW_NUMBER() OVER (ORDER BY (SELECT NULL))
    FROM x_large_table_2
    GROUP BY id
  ) AS x
WHERE rnk <= 2 ;
 
7:11 PM
@ypercubeᵀᴹ I'll play around with it. I have almost no experience with recursive sql, so maybe I'm imagining how it would work wrong
good point about TOP 2, there are some special case optimizations you can do there
I'll do TOP 3 in my question
that second ROW_NUMBER() solution reads all of the rows
 
Yes. because recursive CTEs do not allow TOP in the recursive part, the workaround is to use a subquery with ROW_NUMBER() or some other ranking function. But since you want to to avoid ORDER BY in the queries, a TOP 3 solution would be hard.
Because after one (the CTE) finds 2 values, it's not easy to do "find another that is different from any of the 2 already found"
 
ORDER BY can be used to replace TOP sometimes
but against a heap... not sure what you'd order against
ideally nothing
but I don't think that guarantees that you'll "page through the table"
 
WITH ct AS
  ( SELECT TOP (1) ID, found = 1
    FROM x_large_table_2
  UNION ALL
    SELECT TOP (1) ID, found + 1
    FROM ct CROSS JOIN x_large_table_2 AS x
    WHERE ct.found < 2
      AND x.id NOT IN (SELECT id FROM ct)
  )
SELECT id FROM ct ;
would work I think - if it was allowed.
But it isn't, as far as I know, in SQL Server
and 2 could be replaced by 3, 4, ..., n for TOP (n)
 
7:29 PM
I was thinking something like ORDER BY ? OFFSET N ROWS FETCH FIRST 100000 ROWS ONLY
and you'd keep getting 100k rows until you had enough distinct values
but with a heap there's nothing to order by
have no idea how to code that or if it's allowed
and with a heap each loop gets more expensive
 
You don't have to use ORDER BY.
But I don't see how fetching 100K rows would be efficient
My CTE above could be changed (only to get TOP 2)
WITH ct AS
  ( SELECT TOP (1) ID, found = 1
    FROM x_large_table_2
  UNION ALL
    SELECT TOP (1) ID, found + 1
    FROM ct CROSS JOIN x_large_table_2 AS x
    WHERE ct.found < 2
      AND x.id <> ct.id
  )
SELECT id FROM ct ;
Can you try it?
 
Msg 209, Level 16, State 1, Line 13
Ambiguous column name 'ID'.
Msg 461, Level 16, State 1, Line 9
The TOP or OFFSET operator is not allowed in the recursive part of a recursive common table expression 'ct'.
there goes the OFFSET idea
 
@JoeObbish Oh, yes. Needs: SELECT TOP (1) x.id, found + 1
in the 2nd part
Oh, yes, it needs correction for the TOP as well. What I said a few lines above - and forgot when writing the query
 
@ypercubeᵀᴹ Do you have one in mind? I am very bad with recursive sql
 
WITH ct AS
  ( SELECT TOP (1) ID, found = 1
    FROM x_large_table_2
  UNION ALL
    SELECT y.ID, y.found + 1
    FROM
      ( SELECT x.id, ct.found
        FROM ct CROSS JOIN x_large_table_2 AS x
        WHERE ct.found < 2
          AND x.id <> ct.id
      ) AS y
    WHERE y.rn = 1
  )
SELECT id FROM ct ;
I'm sure Paul will show up any time and solve this with something much easier.
 
7:43 PM
Msg 207, Level 16, State 1, Line 13
Invalid column name 'rn'.
@ypercubeᵀᴹ That would be nice. I've been going through all of the functions and I can find and nothing seems to work. there are some odds rules around DISTINCT
so far I've gotten the best results with %%physloc%%
estimated 5477 distinct values
 
SELECT DISTINCT COUNT(*) OVER (ORDER BY (SELECT NULL))
FROM X_LARGE_TABLE_2
OPTION (MAXDOP 1, QUERYTRACEON 9481)
that gives 5477
looks like some magic value
@ypercubeᵀᴹ Nice
can you do that with TOP 3 easily?
 
Nope
I think I've seen some similar question.
Let me see if I can find it. I know one that had a working solution - but for Postgres.
The recursive CTEs have different limitations there
 
might have something here...
SELECT DISTINCT TOP 2 lag_id
FROM
(
SELECT LAG(ID) OVER (ORDER BY (SELECT NULL)) lag_id
FROM X_LARGE_TABLE_2
) t
WHERE t.lag_id IS NOT NULL
OPTION (MAXDOP 1);
I don't know why it works... but it appears to work
yeah, that does the trick
tried it with TOP 10
logical reads 1 versus logical reads 85228
can write it a bit simpler
SELECT DISTINCT TOP 10 LAG(ID, 0) OVER (ORDER BY (SELECT NULL)) lag_id
FROM X_LARGE_TABLE_3
kind of odd that LAG( , 0) is supported
 
8:01 PM
Why not.
 
@ypercubeᵀᴹ That will always point to the current row?
unless you're saying that the offset could be an expression
and 0 is supported in case it's needed
 
Yes, it could be an expression
 
to avoid something like CASE WHEN OFFSET <> 0 THEN LAG( ...
ok, that seems reasonable
@ypercubeᵀᴹ Thanks again. I'll post it on Monday
the LAG() solution definitely seems hacky, so maybe there's a better one
 
Great
 
8:20 PM
The second query is not even wrong. — ypercubeᵀᴹ 10 secs ago
 
 
2 hours later…
10:26 PM
@JoeObbish check this out:
rextester.com/MTWT95936 (minor correction)
 
@ypercubeᵀᴹ That's really impressive
got a table with 10 distinct values a little more spread out
85228 logical reads for the naive DISTINCT TOP 10 query
15347 for that one
2557 for the LAG one
you should post that as an answer on Monday
 
and execution times?
And note that mine has a limit on how many values it can find, depending on the size of the string values.
If the (2, 3, ..., 10, whatever we are searching for) can't fit into VARCHAR(MAX), we are out of luck!
 
let me check
@ypercubeᵀᴹ CPU time = 969 ms, elapsed time = 975 ms. for LAG
CPU time = 4015 ms, elapsed time = 4023 ms. for recursive query
seems pretty consistent
 
If there is a CI, the recursive can be improved
 
yeah, was just thinking that
you wouldn't have to read the same rows over and over again
 
10:40 PM
(not sure if it will be a better plan but we can try)
@JoeObbish yes, exactly. Not sure if it does that
But it would explain the difference between 1 and 4 seconds
What's the name of the CI ?
 
11:04 PM
@ypercubeᵀᴹ No CI, but I'll add one and give it a try
@ypercubeᵀᴹ LAG solution: logical reads 3040, CPU time = 1016 ms, elapsed time = 1015 ms.
@ypercubeᵀᴹ recursive: logical reads 3204, CPU time = 813 ms, elapsed time = 903 ms.
 
yey !
 
11:24 PM
@ypercubeᵀᴹ CI makes the other solution better too
can get this: logical reads 3040, CPU time = 313 ms, elapsed time = 370 ms.
 
@JoeObbish which one?
 
SELECT DISTINCT TOP 10 ID + SUBSTRING(CAST(UNIQUE_KEY AS VARCHAR(10)), 11, 1)
FROM X_LARGE_TABLE_CI
OPTION (MAXDOP 1);
looks like there's a fair amount of overhead to the LAG(, 0)
well, relative anyway
 
one day I do want to learn how to write recursive sql
 
11:38 PM
@JoeObbish I have the same with with PIVOT
 
@ypercubeᵀᴹ Same what?
 
I can't et my head around PIVOT and UNPIVOT. I need to sit down at some point and learn the syntax, how to write queries
 
@ypercubeᵀᴹ I've never seen a PIVOT query that couldn't be written with GROUP BY
and am not aware of any performance advantages
seems like syntactic sugar
but there might be something out there
 
11:54 PM
I've never seen a performance difference either.
But I have heard unsubstantiated claims from a top tier DBA that PIVOT is the right answer because its performance is way better than group by
 

« first day (2237 days earlier)      last day (2624 days later) »