Using count(*) vs num_rows

后端 未结 5 2468
灰色年华
灰色年华 2021-02-20 10:20

To get number of rows in result set there are two ways:

  1. Is to use query to get count

    $query=\"Select count(*) as count from some_table where type=

5条回答
  •  故里飘歌
    2021-02-20 11:10

    If your goal is to actually count the rows, use COUNT(*). num_rows is ordinarily (in my experience) only used to confirm that more than zero rows were returned and continue on in that case. It will probably take MySQL longer to read out many selected rows compared to the aggregation on COUNT too even if the query itself takes the same amount of time.

提交回复
热议问题