Đừng nghĩ bạn được bao nhiêu điểm. Đừng nghĩ bạn học ở trường nào. Đừng nghĩ bạn tốt nghiệp loại gì. Hãy nghĩ: MÌNH CÓ GÌ TRONG ĐẦU.
Sorry
Đôi khi vì công việc quá bận rộn nên tôi không thể trả lời hết được tất cả các câu hỏi của các bạn. Mong các bạn bỏ quá cho.
Các bạn có thể trả lời các câu hỏi, xin giúp 1 tay!
Trong mysql, em co 1 bang chinh voi 4trieu record, 3 bang phu moi bang khoang 200.000 record. Em da dung index sql, inner join..left, right. Voi hien tai thi em truy van du lieu chay mat khoang 10 phut. Thay co the cho em viet co cach nao truy van voi so luong record nhieu nhu vay trong thoi gian it nhat ko thay??
Thay co the cho em vai solution ve truong hop ntn ko thay?
Scenario:
We have
– A DB Client that stores the info like: phone number (MSISDN), email, sex (male, female,…), age, city, date of birth,…
– A DB Target that stores the info of Client (phone number or MSISDN) that receive the ad of which DEMAND. To avoid storing huge data in a table, we split into many tables based on its ID. The format is DEMAND_XYZ in which XYZ stands for ID
Ex: DEMAND_230 (MSISDN), DEMAND_130 (MSISDN), DEMAND_12 (MSISDN)
Some definitions:
Include demands: Select the clients that are available in the demands
E.g.: Include demand_230, demand_130: 0918475896, 0928475896, 0938335896
Exclude demands: Select the clients that are not available in the demands
E.g.: Exclude demand_230, demand_130: All the clients except 0918475896, 0928475896, 0938335896
Data to test:
Table CLIENT has 3.479.583 records. Indexed: MSISDN
Table DEMAND_120 has 100.000 records. Indexed: MSISDN
Table DEMAND_125 has 100.000 records. Indexed: MSISDN
Table DEMAND_150 has 100.000 records. Indexed: MSISDN
Table DEMAND_160 has 100.000 records. Indexed: MSISDN
We want to include demands 150,160 and exclude 120,125
Solution 1: (implemented in production)
SELECT SQL_NO_CACHE DISTINCT CLIENT.MSISDN
FROM CLIENT
LEFT JOIN
(
SELECT MSISDN FROM DEMAND_150
UNION
SELECT MSISDN FROM DEMAND_160
) A ON A.MSISDN = CLIENT.MSISDN
LEFT JOIN
(
SELECT MSISDN FROM DEMAND_120
UNION
SELECT MSISDN FROM DEMAND_150
) B ON B.MSISDN = CLIENT.MSISDN
WHERE B.MSISDN IS NULL AND A.MSISDN IS NOT NULL
Time respond: Unknown, we were not patient enough to wait until the script finished
Solution 2:
SELECT SQL_NO_CACHE DISTINCT CLIENT.MSISDN
FROM CLIENT
WHERE (
CLIENT.MSISDN IN ( SELECT MSISDN FROM DEMAND_150 ) OR
CLIENT.MSISDN IN ( SELECT MSISDN FROM DEMAND_160 )
) AND
CLIENT.MSISDN NOT IN (SELECT MSISDN FROM DEMAND_120 ) AND
CLIENT.MSISDN NOT IN ( SELECT MSISDN FROM DEMAND_125 )
Time respond: 6m37s
Solution 3:
SELECT SQL_NO_CACHE DISTINCT CLIENT.MSISDN
FROM CLIENT
LEFT JOIN DEMAND_150 B ON B.MSISDN = CLIENT.MSISDN
LEFT JOIN DEMAND_160 D ON D.MSISDN = CLIENT.MSISDN
LEFT JOIN DEMAND_120 C ON C.MSISDN = CLIENT.MSISDN
LEFT JOIN DEMAND_125 A ON A.MSISDN = CLIENT.MSISDN
WHERE
C.MSISDN IS NULL AND
A.MSISDN IS NULL AND
(B.MSISDN IS NOT NULL OR D.MSISDN IS NOT NULL)
Time respond: 3m25s
Solution 4:
We store all the demands into one table instead of splitting to many tables based on its ID. In the ALL_DEMAND table we use partition based on ID_DEMAND
ALL_DEMAND (MSISDN, ID_DEMAND) : Indexed by MSISDN, Indexed by ID_DEMAND
We create fake data for this table: 500 demands x 100.000 records for each demand = 50.000.000 rows
SELECT SQL_NO_CACHE DISTINCT CLIENT.MSISDN
FROM CLIENT
INNER JOIN ALL_DEMAND DEMANDS1 ON DEMANDS1.ID_DEMAND IN (150,160) AND CLIENT.MSISDN = DEMANDS1.MSISDN
LEFT JOIN ALL_DEMAND DEMANDS2 ON DEMANDS2.ID_DEMAND IN (120,125) AND CLIENT.MSISDN = DEMANDS2.MSISDN
WHERE DEMANDS2.MSISDN IS NULL
Time respond: 50s
====
Thay xem dum em va cho em solution voi thay. Chao than ai thay.
Head First Java, 2nd Edition
Kathy Sierra and Bert Bates
09-Feb-2005
Vậy làm sao e lấy được giá trị của node attribute “id” như trên với jsp java hả thầy?
thầy giúp e với, e tìm hoài mà ko thấy demo nào như vậy.
E cảm ơn thầy nhiều.
Hic cái vụ read data trong mysql với số lượng lớn như vậy mà có sử dụng join thì thời gian lâu là phải rùi, nếu độc cùng lúc lên một lần data thì phải mất thời gian chưa kể phải chạy qua môi trường mạng bị tác động. Trong ms sql có giải pháp load từng đoạn dữ liệu lên, và sau đó nối ghép chúng lại sau, mỗi lần lấy lên bao nhiêu recode thì tùy bạn. Nhưng trong mysql thì ko biết có vụ này không nữa. Có thể dùng transaction lập trình thủ tục riêng để lấy data theoo ý, hoặc có thể sử dụng phân đoạn bảng theo cột để cải thiện tốc độ vì đôi khi chỉ sử dụng những cột thường xuyên, trích: http://www.nghean-aptech.com/laptrinh/2011/1490/default.aspx
Mai Duong said
thầy ơi, sao không có hướng dẫn tạo file xml từ jsp? thầy cho em tài liệu này được không?
cám ơn thầy
Đào Tăng Toàn said
thay oi cho em hoi khong hieu cai mon XMLJ thi cai gi nhi
Như Khánh said
thầy cho em hỏi là XML này trong lập trình web giống như là tạo Thẻ cho lập trình web phải hok ???
Võ Văn Hải said
XML cũng như HTML là tập con của SGML, tuy nhiên cấu trúc của XML chặc chẽ hơn rất nhiều. Bạn đọc thêm về XML sẽ thấy nhiều điều hay cực!
Nguyen Viet Tram said
Thay giup em 1 so van de nay voi:
Trong mysql, em co 1 bang chinh voi 4trieu record, 3 bang phu moi bang khoang 200.000 record. Em da dung index sql, inner join..left, right. Voi hien tai thi em truy van du lieu chay mat khoang 10 phut. Thay co the cho em viet co cach nao truy van voi so luong record nhieu nhu vay trong thoi gian it nhat ko thay??
Thay co the cho em vai solution ve truong hop ntn ko thay?
Em rat mong nhan dc cau tra loi som tu thay.
Nguyen Viet Tram
Nguyen Viet Tram said
Than thay, cau truc sql em nhu sau:
Scenario:
We have
– A DB Client that stores the info like: phone number (MSISDN), email, sex (male, female,…), age, city, date of birth,…
– A DB Target that stores the info of Client (phone number or MSISDN) that receive the ad of which DEMAND. To avoid storing huge data in a table, we split into many tables based on its ID. The format is DEMAND_XYZ in which XYZ stands for ID
Ex: DEMAND_230 (MSISDN), DEMAND_130 (MSISDN), DEMAND_12 (MSISDN)
For example:
CLIENT (MSISDN, EMAIL, SEX…..) = (0918475896, abc@dirox.net, male…), (0928475896, edf@dirox.net, male…), (0938335896, xyz@dirox.net, female…)
DEMAND_230 (MSISDN) = (0918475896), (0928475896)
DEMAND_130 (MSISDN) = (0918475896), (0938335896)
Some definitions:
Include demands: Select the clients that are available in the demands
E.g.: Include demand_230, demand_130: 0918475896, 0928475896, 0938335896
Exclude demands: Select the clients that are not available in the demands
E.g.: Exclude demand_230, demand_130: All the clients except 0918475896, 0928475896, 0938335896
Data to test:
Table CLIENT has 3.479.583 records. Indexed: MSISDN
Table DEMAND_120 has 100.000 records. Indexed: MSISDN
Table DEMAND_125 has 100.000 records. Indexed: MSISDN
Table DEMAND_150 has 100.000 records. Indexed: MSISDN
Table DEMAND_160 has 100.000 records. Indexed: MSISDN
We want to include demands 150,160 and exclude 120,125
Solution 1: (implemented in production)
SELECT SQL_NO_CACHE DISTINCT CLIENT.MSISDN
FROM CLIENT
LEFT JOIN
(
SELECT MSISDN FROM DEMAND_150
UNION
SELECT MSISDN FROM DEMAND_160
) A ON A.MSISDN = CLIENT.MSISDN
LEFT JOIN
(
SELECT MSISDN FROM DEMAND_120
UNION
SELECT MSISDN FROM DEMAND_150
) B ON B.MSISDN = CLIENT.MSISDN
WHERE B.MSISDN IS NULL AND A.MSISDN IS NOT NULL
Time respond: Unknown, we were not patient enough to wait until the script finished
Solution 2:
SELECT SQL_NO_CACHE DISTINCT CLIENT.MSISDN
FROM CLIENT
WHERE (
CLIENT.MSISDN IN ( SELECT MSISDN FROM DEMAND_150 ) OR
CLIENT.MSISDN IN ( SELECT MSISDN FROM DEMAND_160 )
) AND
CLIENT.MSISDN NOT IN (SELECT MSISDN FROM DEMAND_120 ) AND
CLIENT.MSISDN NOT IN ( SELECT MSISDN FROM DEMAND_125 )
Time respond: 6m37s
Solution 3:
SELECT SQL_NO_CACHE DISTINCT CLIENT.MSISDN
FROM CLIENT
LEFT JOIN DEMAND_150 B ON B.MSISDN = CLIENT.MSISDN
LEFT JOIN DEMAND_160 D ON D.MSISDN = CLIENT.MSISDN
LEFT JOIN DEMAND_120 C ON C.MSISDN = CLIENT.MSISDN
LEFT JOIN DEMAND_125 A ON A.MSISDN = CLIENT.MSISDN
WHERE
C.MSISDN IS NULL AND
A.MSISDN IS NULL AND
(B.MSISDN IS NOT NULL OR D.MSISDN IS NOT NULL)
Time respond: 3m25s
Solution 4:
We store all the demands into one table instead of splitting to many tables based on its ID. In the ALL_DEMAND table we use partition based on ID_DEMAND
ALL_DEMAND (MSISDN, ID_DEMAND) : Indexed by MSISDN, Indexed by ID_DEMAND
We create fake data for this table: 500 demands x 100.000 records for each demand = 50.000.000 rows
SELECT SQL_NO_CACHE DISTINCT CLIENT.MSISDN
FROM CLIENT
INNER JOIN ALL_DEMAND DEMANDS1 ON DEMANDS1.ID_DEMAND IN (150,160) AND CLIENT.MSISDN = DEMANDS1.MSISDN
LEFT JOIN ALL_DEMAND DEMANDS2 ON DEMANDS2.ID_DEMAND IN (120,125) AND CLIENT.MSISDN = DEMANDS2.MSISDN
WHERE DEMANDS2.MSISDN IS NULL
Time respond: 50s
====
Thay xem dum em va cho em solution voi thay. Chao than ai thay.
Võ Văn Hải said
Bạn nào giúp dùm với. Mình bận quá.
hieu nt said
Thầy ơi, e có file xml dạng:
Head First Java, 2nd Edition
Kathy Sierra and Bert Bates
09-Feb-2005
Vậy làm sao e lấy được giá trị của node attribute “id” như trên với jsp java hả thầy?
thầy giúp e với, e tìm hoài mà ko thấy demo nào như vậy.
E cảm ơn thầy nhiều.
hieu nt said
Hix, file xml post lên bị đổi rồi. E post lại ngen, àh, với DOM ngen thầy:
”
Head First Java, 2nd Edition
Kathy Sierra and Bert Bates
09-Feb-2005
“
Võ Văn Hải said
tui không thấy file XML. bạn có thể dùng cách viết sau để hiển thị xml:
tài liệu XML của bạn ở đây[/source code]
nhớ viết liền chữ sourcecode lại.
Thanh Nguyen Truong said
Hic cái vụ read data trong mysql với số lượng lớn như vậy mà có sử dụng join thì thời gian lâu là phải rùi, nếu độc cùng lúc lên một lần data thì phải mất thời gian chưa kể phải chạy qua môi trường mạng bị tác động. Trong ms sql có giải pháp load từng đoạn dữ liệu lên, và sau đó nối ghép chúng lại sau, mỗi lần lấy lên bao nhiêu recode thì tùy bạn. Nhưng trong mysql thì ko biết có vụ này không nữa. Có thể dùng transaction lập trình thủ tục riêng để lấy data theoo ý, hoặc có thể sử dụng phân đoạn bảng theo cột để cải thiện tốc độ vì đôi khi chỉ sử dụng những cột thường xuyên, trích: http://www.nghean-aptech.com/laptrinh/2011/1490/default.aspx