-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
order by rand() don't return random value #9033
Comments
@WangXiangUSTC select a from test1 order by rand() limit 10;
select a from test1 order by 0 limit 10;
select a from test1 order by a limit 10; |
but mysql can get random value use this sql @XuHuaiyu |
@WangXiangUSTC |
I ran into this same problem today also where TiDB doesn't behave as MySQL does. As per the document link @XuHuaiyu quoted it states;
This is commonly used to select a random number of rows from a table. @dbjoa a reproducible scenario is; Create schema and insert values
Then randomly select 2 rows from table tmprand
When running the above select query multiple times TiDB will always output the same result of "a" and "b". When running the same query on MySQL it will output 2 random rows, eg:
|
maybe we can workaround by use sub query like this it seems to be caused by miss a project in plan result:
it should be like this:
|
@lysu yes, that sub query workaround does the job. In my case the dataset was small and doesn't change much so I worked around it by caching the table in |
I want get random value by
order by rand()
I use the sql below to get some random values.
I want to see random result in column a.
I run many times, and the result is same.
tidb-server -V
or runselect tidb_version();
on TiDB)?tidb version: v2.1.2
The text was updated successfully, but these errors were encountered: