久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      • <bdo id='PPI4U'></bdo><ul id='PPI4U'></ul>

      1. <legend id='PPI4U'><style id='PPI4U'><dir id='PPI4U'><q id='PPI4U'></q></dir></style></legend>
        <i id='PPI4U'><tr id='PPI4U'><dt id='PPI4U'><q id='PPI4U'><span id='PPI4U'><b id='PPI4U'><form id='PPI4U'><ins id='PPI4U'></ins><ul id='PPI4U'></ul><sub id='PPI4U'></sub></form><legend id='PPI4U'></legend><bdo id='PPI4U'><pre id='PPI4U'><center id='PPI4U'></center></pre></bdo></b><th id='PPI4U'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='PPI4U'><tfoot id='PPI4U'></tfoot><dl id='PPI4U'><fieldset id='PPI4U'></fieldset></dl></div>
      2. <tfoot id='PPI4U'></tfoot>

        <small id='PPI4U'></small><noframes id='PPI4U'>

        MySQL:ORDER BY RAND() 的替代方案

        MySQL: Alternatives to ORDER BY RAND()(MySQL:ORDER BY RAND() 的替代方案)

              <tbody id='zxYNO'></tbody>

            <small id='zxYNO'></small><noframes id='zxYNO'>

            <i id='zxYNO'><tr id='zxYNO'><dt id='zxYNO'><q id='zxYNO'><span id='zxYNO'><b id='zxYNO'><form id='zxYNO'><ins id='zxYNO'></ins><ul id='zxYNO'></ul><sub id='zxYNO'></sub></form><legend id='zxYNO'></legend><bdo id='zxYNO'><pre id='zxYNO'><center id='zxYNO'></center></pre></bdo></b><th id='zxYNO'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='zxYNO'><tfoot id='zxYNO'></tfoot><dl id='zxYNO'><fieldset id='zxYNO'></fieldset></dl></div>

              <legend id='zxYNO'><style id='zxYNO'><dir id='zxYNO'><q id='zxYNO'></q></dir></style></legend>
              <tfoot id='zxYNO'></tfoot>
                  <bdo id='zxYNO'></bdo><ul id='zxYNO'></ul>
                  本文介紹了MySQL:ORDER BY RAND() 的替代方案的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我已經(jīng)閱讀了 MySQL ORDER BY RAND() 函數(shù)的一些替代方案,但大多數(shù)替代方案僅適用于需要單個(gè)隨機(jī)結(jié)果的地方.

                  I've read about a few alternatives to MySQL's ORDER BY RAND() function, but most of the alternatives apply only to where on a single random result is needed.

                  有誰知道如何優(yōu)化返回多個(gè)隨機(jī)結(jié)果的查詢,例如:

                  Does anyone have any idea how to optimize a query that returns multiple random results, such as this:

                     SELECT u.id, 
                            p.photo 
                       FROM users u, profiles p 
                      WHERE p.memberid = u.id 
                        AND p.photo != '' 
                        AND (u.ownership=1 OR u.stamp=1) 
                   ORDER BY RAND() 
                      LIMIT 18 
                  

                  推薦答案

                  UPDATE 2016

                  此解決方案在使用索引列時(shí)效果最佳.

                  這里是一個(gè)簡(jiǎn)單的例子,優(yōu)化的查詢平臺(tái)標(biāo)有 100,000 行.

                  Here is a simple example of and optimized query bench marked with 100,000 rows.

                  優(yōu)化:300 毫秒

                  SELECT 
                      g.*
                  FROM
                      table g
                          JOIN
                      (SELECT 
                          id
                      FROM
                          table
                      WHERE
                          RAND() < (SELECT 
                                  ((4 / COUNT(*)) * 10)
                              FROM
                                  table)
                      ORDER BY RAND()
                      LIMIT 4) AS z ON z.id= g.id
                  

                  注意限制數(shù)量:限制 4 和 4/count(*).4s 必須是相同的數(shù)字.更改返回的數(shù)量不會(huì)對(duì)速度產(chǎn)生太大影響.限制 4 和限制 1000 的基準(zhǔn)是相同的.限制 10,000 花了 600 毫秒

                  note about limit ammount: limit 4 and 4/count(*). The 4s need to be the same number. Changing how many you return doesn't effect the speed that much. Benchmark at limit 4 and limit 1000 are the same. Limit 10,000 took it up to 600ms

                  關(guān)于加入的注意事項(xiàng):僅隨機(jī)化 id 比隨機(jī)化整行更快.由于它必須將整行復(fù)制到內(nèi)存中,然后對(duì)其進(jìn)行隨機(jī)化.聯(lián)接可以是鏈接到子查詢的任何表,以防止表掃描.

                  note about join: Randomizing just the id is faster than randomizing a whole row. Since it has to copy the entire row into memory then randomize it. The join can be any table that is linked to the subquery Its to prevent tablescans.

                  注意 where 子句:where 計(jì)數(shù)限制了隨機(jī)結(jié)果的數(shù)量.它會(huì)根據(jù)結(jié)果的百分比對(duì)它們進(jìn)行排序,而不是對(duì)整個(gè)表格進(jìn)行排序.

                  note where clause: The where count limits down the ammount of results that are being randomized. It takes a percentage of the results and sorts them rather than the whole table.

                  注意子查詢:如果執(zhí)行連接和額外的 where 子句條件,您需要將它們同時(shí)放在子查詢和子子查詢中.進(jìn)行準(zhǔn)確的計(jì)數(shù)并拉回正確的數(shù)據(jù).

                  note sub query: The if doing joins and extra where clause conditions you need to put them both in the subquery and the subsubquery. To have an accurate count and pull back correct data.

                  未優(yōu)化:1200 毫秒

                  SELECT 
                      g.*
                  FROM
                      table g
                  ORDER BY RAND()
                  LIMIT 4
                  

                  優(yōu)點(diǎn)

                  order by rand() 快 4 倍.此解決方案適用于任何帶有索引列的表.

                  4x faster than order by rand(). This solution can work with any table with a indexed column.

                  缺點(diǎn)

                  復(fù)雜查詢有點(diǎn)復(fù)雜.需要在子查詢中維護(hù)2個(gè)代碼庫

                  It is a bit complex with complex queries. Need to maintain 2 code bases in the subqueries

                  這篇關(guān)于MySQL:ORDER BY RAND() 的替代方案的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數(shù)根據(jù) N 個(gè)先前值來決定接下來的 N 個(gè)行)
                  reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達(dá)式的結(jié)果;條款?)
                  Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數(shù)的 ignore 選項(xiàng)是忽略整個(gè)事務(wù)還是只是有問題的行?) - IT屋-程序員軟件開發(fā)技
                  Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時(shí)出錯(cuò),使用 for 循環(huán)數(shù)組)
                  pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調(diào)用 o23.load 時(shí)發(fā)生錯(cuò)誤 沒有合適的驅(qū)動(dòng)程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數(shù)據(jù)庫表作為 Spark 數(shù)據(jù)幀讀取?)

                      • <i id='knltt'><tr id='knltt'><dt id='knltt'><q id='knltt'><span id='knltt'><b id='knltt'><form id='knltt'><ins id='knltt'></ins><ul id='knltt'></ul><sub id='knltt'></sub></form><legend id='knltt'></legend><bdo id='knltt'><pre id='knltt'><center id='knltt'></center></pre></bdo></b><th id='knltt'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='knltt'><tfoot id='knltt'></tfoot><dl id='knltt'><fieldset id='knltt'></fieldset></dl></div>

                      • <tfoot id='knltt'></tfoot>

                        <small id='knltt'></small><noframes id='knltt'>

                          <tbody id='knltt'></tbody>

                          <legend id='knltt'><style id='knltt'><dir id='knltt'><q id='knltt'></q></dir></style></legend>
                          • <bdo id='knltt'></bdo><ul id='knltt'></ul>
                          • 主站蜘蛛池模板: 日韩欧美网 | 又爽又黄axxx片免费观看 | 亚洲成人福利在线观看 | 亚洲激情视频在线 | 天天操夜夜拍 | 超碰伊人久久 | 日韩欧美中文字幕在线视频 | 亚洲高清在线观看 | 亚洲人人 | 99一级毛片 | 最新中文字幕在线 | www.色综合| 黄色av网站在线免费观看 | 中文字幕视频网 | av片网| 欧美精品一二三区 | 亚洲精品国产精品国自产在线 | 精品久久久久久久久久久 | 日韩视频在线观看一区二区 | 亚洲一区三区在线观看 | 福利影院在线看 | 亚洲精品乱 | 三级黄色片在线观看 | h网站在线观看 | 亚洲视频 欧美视频 | 午夜免费观看体验区 | 九九综合 | 亚洲精品视频在线播放 | 先锋av资源网 | 久久精品播放 | 一区二区视频在线 | 91丨九色丨国产在线 | 91精品国产91久久久久福利 | 美女毛片免费看 | 精品一区二区久久久久久久网站 | 亚洲欧美在线观看 | 日韩精品一区二区三区久久 | 精品一区二区在线视频 | 91免费福利视频 | 国产精品久久久久久久免费观看 | 日韩综合 |