1

我为一家拥有大约 150 家酒店的旅行社开发了一个使用 php 和 mysql 管理酒店价格、分配和预订的系统。由于酒店房价因日期而异,表设计大致如下

hotel_tbl{
 hotel_id,
 hotel_name
}    

room_type_tbl{
 room_type_id,
 room_type_name,
 hotel_id 
}


room_rates_tbl{
  room_type_id,
  **from_date,
  **till_date,
  meal_basis,//(Breakfast,halfboard,fullboard) BB,HB,FB
  sleeps,//(Single,Double,Triple) SGL,DBL,TPL
  currency,
  room_rate
}

由于酒店价格随日期波动,当我查询表格以进行复杂的旅游套餐计算(涉及多家酒店)时,我注意到性能比预期的要慢。我的问题是,如果我在每个日期都有一个价格行而不是使用日期范围(我的系统包含大约 150 家酒店),您认为性能会提高吗,如下所示:

room_rates_tbl { // A row for each day as opposed to using a date range
  room_type_id,
  **date,
  meal_basis,//(Breakfast,halfboard,fullboard) BB,HB,FB
  sleeps,//(Single,Double,Triple) SGL,DBL,TPL
  currency,
  room_rate}

希望问题足够清楚...

我已经更新了我的问题以使其更清楚。房间类型例如是“标准房”或“豪华房”或“家庭房”,睡眠将包含单人房、双人房等。我已从问题中删除了 market_type,因为它与市场组无关(例如国家)的费率是 targarted。我的问题是在查询费率表时,存储日期费率是否比使用日期范围更有效。

4

2 回答 2

1

Let's assume that your query is for a particular type of room for all hotels between two given dates. What do you need to get from the database? I would suggest:

  1. The rate for that type of room for all hotels on the start date
  2. The rate for that type of room for all hotels on the end date

You want avoid table scans, because these slow down your response to the user. So any lookup needs to use an index. Since the query is based on dates, the date field should be indexed. So if the user wants a room between 31/12/12 and 05/01/13, we can use range operators over the index as described in http://dev.mysql.com/doc/refman/5.1/en/range-optimization.html#range-access-single-part). (If you store the date value as a timestamp value, you reduce the storage size of the values, which should improve the performance of the index.) If you use your original table schema, you'll need two indexes - one on start date and one on end date - but fewer rows in the table, compared with the amended table you suggest, which will need one index but more table rows (one for each day etc.) It's too variable to suggest which one will perform better.

于 2012-05-16T09:24:11.483 回答
0

我认为将您的日期和费率分开到另一个表中会更好。

room_tbl - room_id , room_type_id, market_type_id & 任何房间信息

room_rate_tbl - room_id,from_date,till_date,货币,room_rate

这样您的房间信息是独立的,您可以轻松地将任何房价添加、编辑、删除到特定的 room_id。

于 2012-05-16T07:57:35.593 回答