ï»??xml version="1.0" encoding="utf-8" standalone="yes"?>伊人久久大香线蕉综合四虎小说,亚洲成人av在线,一区二区三区四区欧美日韩http://www.aygfsteel.com/shijian/category/46849.htmlzh-cnThu, 29 Mar 2012 08:19:24 GMTThu, 29 Mar 2012 08:19:24 GMT60歪歪之数据库http://www.aygfsteel.com/shijian/archive/2010/11/07/337464.html矛_¾åŒå­¦çŸ›_¾åŒå­¦Sun, 07 Nov 2010 09:53:00 GMThttp://www.aygfsteel.com/shijian/archive/2010/11/07/337464.htmlhttp://www.aygfsteel.com/shijian/comments/337464.htmlhttp://www.aygfsteel.com/shijian/archive/2010/11/07/337464.html#Feedback0http://www.aygfsteel.com/shijian/comments/commentRss/337464.htmlhttp://www.aygfsteel.com/shijian/services/trackbacks/337464.html题记åQšä¸»è¦è®°å½•同学分享的关于数据库设计方面的内容åQŒæ€è€ƒè¿‡ä¸€ç‚¹ï¼Œè®°å½•下来ã€?br />
一、从需求开始,考虑数据库的设计åQŒä¸”¾l“合具体数据库特æ€?br />
  ä¸€ä¸ªè®ºå›ï¼Œè¦æ±‚昄¡¤ºå¸–子的æ€ÀL¡æ•ŽÍ¼Œå¯¹äºŽmysql、innodb引擎åQ›ä¸Š¾U¿å‰æœŸå®Œå…¨æ²¡æœ‰é—®é¢˜ï¼Œå½“äh气积累,帖子辑ֈ°åƒä¸‡¾U§åˆ«æ—Óž¼Œæ­¤æ—¶æ€§èƒ½çš„问题就会显现出来。好的设计,是需求阶ŒDµå°±è¦è€ƒè™‘的。对于我åQŒè¿™æ˜¯ä¸€ä¸ªæ€æƒ³æ¦‚念上的转变ã€?br />   ä½†å¼•擎如果换成myisamåQŒå°±½Ž—数据达åˆîCº¿çš„çñ”别,“¾lŸè®¡æ€ÀL•°”˜q™æ ·çš„问题还会存在吗 åQŸä¸ä¼šï¼Œmyisam自èínž®×ƒ¼š¾l´æŠ¤æ€ÀL•°ä¿¡æ¯ã€‚因此设计,必须¾l“合具体的数据库的特性来做,不能以一概全ã€?br />
二、应该遵循原åˆ?åQˆæœªéªŒè¯åQ?br />
  1.ž®ç»“果集驱动大结果集。理由:mysql的连接查询原ç?åQ?br />   2.ž®½å¯èƒ½åœ¨ç´¢å¼•中完成排序。理由:索引本èínž®±æ˜¯æœ‰åºçš?br />   3.只取自己需要的column åQ?br />   4.避免复杂的连接查询和子查询ã€?br />   5.适当的数据冗ä½?理由åQšå¸–子表&用户表,如果帖子表拥有usernameåQŒåˆ™æ¯æ¬¡å¸–子的显½Cºæ˜¯ä¸éœ€è¦è¿žæŽ¥æŸ¥è¯¢èŽ·å–usernameã€?nbsp;
  6.应用层的cahce机制 åQ?br />
三、概�br />
  1.垂直拆分åQ?span style="font-size: 12px; font-family: Arial, sans-serif, Helvetica, Tahoma; line-height: 18px; ">按列˜q›è¡Œåˆ†å‰²åQŒå³æŠŠä¸€æ¡è®°å½•分开多个地方保存åQŒæ¯ä¸ªå­è¡¨çš„行数相同ã€?/span>帖子表,id、userid、username、content、xxx ...前面4个字ŒDµå¾ˆå¸¸ç”¨åQŒä½†æ˜¯åŽé¢xxx½{‰å¾ˆå¤šå­—ŒDµï¼Œä¸å¸¸ç”¨ï¼Œæ•°æ®é‡å¾ˆå¤§ã€‚进行垂直拆分,table1字段包含“id、userid、username、content”,table2包含“xxxã€?..”½{‰ä¸å¸¸ç”¨å­—段。优点:减少io的操作。缺点:如果需要不常用字段信息åQŒéœ€è¦è¿žè¡¨æŸ¥è¯¢ã€?br />   2.æ°´åã^拆分åQ?/span>按记录进分分å‰ÔŒ¼Œä¸åŒçš„记录分开保存åQŒæ¯ä¸ªå­è¡¨çš„列数相同。比如:淘宝的用户交易数据,æ ÒŽ®ç”¨æˆ·id取模åQŒç¡®å®šå…·ä½“的数据存放在那个数据库。水òqÏx‹†åˆ†ä¼š¾l™åº”用带来复杂性ã€?br />   3.集群åQšæé«˜ç³»¾lŸçš„可用性。分库的节点引入多台机器åQŒæ¯å°æœºå™¨ä¿ å­˜çš„æ•°æ®æ˜¯ä¸€æ øP¼Œè´Ÿè²å‡è¡¡åœ¨å¤šå°æœºå™¨ã€‚如何均衡、探‹¹‹æœºå™¨çš„可用性,是新的问é¢?åQ?br />   4.ä¸Õd¤‡åQšä¸€èˆ¬çš„互联¾|‘应用中åQ?strong style="font-weight: bold; ">¾lè¿‡ä¸€äº›æ•°æ®è°ƒæŸ¥å¾—出结论,è¯?写的比例大概åœ?10åQ?å·¦å³ã€‚äØ“ä»€ä¹ˆè¦è¯Õd†™åˆ†ç¦»åQ?/strong>写操作涉及到锁的问题åQŒä¸½Ž¡æ˜¯è¡Œé”˜q˜æ˜¯è¡¨é”˜q˜æ˜¯å—锁åQŒåœ¨å¤§åƈ发的情况下,效率很低。写操作集中在一个节点上åQŒè€Œè¯»æ“ä½œå…¶å…¶ä»?çš„N个节点上˜q›è¡Œã€‚读写分¼›Õd¼•入的新问题:比如我的Master上的数据怎样和集¾Ÿ¤ä¸­å…¶å®ƒSlave机器保持数据的同步和一致呢?






]]>
sql˜qžæŽ¥æŸ¥è¯¢http://www.aygfsteel.com/shijian/archive/2010/11/03/336935.html矛_¾åŒå­¦çŸ›_¾åŒå­¦Wed, 03 Nov 2010 07:36:00 GMThttp://www.aygfsteel.com/shijian/archive/2010/11/03/336935.htmlhttp://www.aygfsteel.com/shijian/comments/336935.htmlhttp://www.aygfsteel.com/shijian/archive/2010/11/03/336935.html#Feedback0http://www.aygfsteel.com/shijian/comments/commentRss/336935.htmlhttp://www.aygfsteel.com/shijian/services/trackbacks/336935.html请参考:http://en.wikipedia.org/wiki/Join_(SQL)#Sample_tables

inner JOINS

  An inner join is the most common join operation used in applications and can be regarded as the default join-type. Inner join creates a new result table by combining column values of two tables (A and B) based upon the join-predicate. The query compares each row of A with each row of B to find all pairs of rows which satisfy the join-predicate. When the join-predicate is satisfied, column values for each matched pair of rows of A and B are combined into a result row. The result of the join can be defined as the outcome of first taking the Cartesian product (or cross-join) of all records in the tables (combining every record in table A with every record in table B)—then return all records which satisfy the join predicate. Actual SQL implementations normally use other approaches like a Hash join or a Sort-merge join where possible, since computing the Cartesian product is very inefficient.

  æ³¨æ„åQšinnner查询åQˆé»˜è®¤çš„˜qžæŽ¥æŸ¥è¯¢æ–¹å¼åQ‰ï¼Œæ˜¯å…ˆæŸ¥è¯¢“Cartesian”生成中间表,再根据where条äšg½{›é€‰ç»“果;但此æ–ÒŽ³•非常低效åQŒSQL具体的实现可能是 Hash join or a Sort-merge join ã€?br />         One can further classify inner joins as equi-joins, as natural joins, or as cross-joins.

SELECT *
FROM employee INNER JOIN department
ON employee.DepartmentID = department.DepartmentID;
The following example shows a query which is equivalent to the one from the previous example.

SELECT *
FROM   employee, department
WHERE  employee.DepartmentID = department.DepartmentID;

Outer joins

  An outer join does not require each record in the two joined tables to have a matching record. The joined table retains each record—even if no other matching record exists. Outer joins subdivide further into left outer joins, right outer joins, and full outer joins, depending on which table(s) one retains the rows from (left, right, or both).

Example of a left outer join, with the additional result row italicized:

SELECT *
FROM   employee  LEFT OUTER JOIN department
ON employee.DepartmentID = department.DepartmentID;
Employee.LastNameEmployee.DepartmentIDDepartment.DepartmentNameDepartment.DepartmentID
Jones 33 Engineering 33
Rafferty 31 Sales 31
Robinson 34 Clerical 34
Smith 34 Clerical 34
John NULL NULL NULL
Steinberg 33 Engineering 33


Example right outer join, with the additional result row italicized:

SELECT *
FROM   employee RIGHT OUTER JOIN department
ON employee.DepartmentID = department.DepartmentID;
Employee.LastNameEmployee.DepartmentIDDepartment.DepartmentNameDepartment.DepartmentID
Smith 34 Clerical 34
Jones 33 Engineering 33
Robinson 34 Clerical 34
Steinberg 33 Engineering 33
Rafferty 31 Sales 31
NULL NULL Marketing 35


Example full outer join: åQˆmysql is not supportåQ?/p>

SELECT *
FROM   employee
FULL OUTER JOIN department
ON employee.DepartmentID = department.DepartmentID;
Employee.LastNameEmployee.DepartmentIDDepartment.DepartmentNameDepartment.DepartmentID
Smith 34 Clerical 34
Jones 33 Engineering 33
Robinson 34 Clerical 34
John NULL NULL NULL
Steinberg 33 Engineering 33
Rafferty 31 Sales 31
NULL NULL Marketing 35


Self-join

A query to find all pairings of two employees in the same country is desired.

An example solution query could be as follows:

SELECT F.EmployeeID, F.LastName, S.EmployeeID, S.LastName, F.Country
FROM Employee F, Employee S
WHERE F.Country = S.Country
AND F.EmployeeID < S.EmployeeID
ORDER BY F.EmployeeID, S.EmployeeID;

Which results in the following table being generated.

Employee Table after Self-join by Country
EmployeeIDLastNameEmployeeIDLastNameCountry
123 Rafferty 124 Jones Australia
123 Rafferty 145 Steinberg Australia
124 Jones 145 Steinberg Australia
305 Smith 306 John Germany










Join algorithms

Three fundamental algorithms exist for performing a join operation: Nested loop joinSort-merge join and Hash join.




 



]]>
Ö÷Õ¾Ö©Öë³ØÄ£°å£º Ó¢³¬| Т²ýÏØ| ºìÇÅÇø| ¶«ÐËÊÐ| ºªµ¦ÏØ| ÈðÀöÊÐ| ÆÖ¶«ÐÂÇø| »³ÈÊÏØ| ÙÈʦÊÐ| ͨÐíÏØ| Ô«ÇúÏØ| ³£ÖÝÊÐ| ÕýÑôÏØ| ÄÚÏçÏØ| ÖÓÉ½ÏØ| Ã÷¹âÊÐ| ËïÎâÏØ| Æ«¹ØÏØ| Ä«ÓñÏØ| Í¼Ä¾Êæ¿ËÊÐ| ÉÛÎäÊÐ| Ú«ºÓÊÐ| À­×ÎÏØ| ÏæÌ¶ÏØ| ÔúÂ³ÌØÆì| ÕòÔ­ÏØ| ÙÙÖÝÊÐ| °ØÏçÏØ| ÍòÊ¢Çø| ±±³½Çø| Ã÷ÏªÏØ| ¸ÊÈªÏØ| ÔæÇ¿ÏØ| µç°×ÏØ| ÀàÎÚÆëÏØ| ËÕÄáÌØÓÒÆì| áªÉ½ÏØ| »ªÍ¤ÏØ| ºº¹ÁÇø| ÓÜÊ÷ÊÐ| Î÷ÎÚÖéÄÂÇ߯ì|