Commit 1764ba15 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Some optimization. Here are the details:

* SQLDict_assignMessage.zsql

Avoid unnecessary assignments. Reduce message size.

* SQLDict_setPriority.zsql

Reduce message size.

* SQLDict_readMessageList.zsql

Remove unnecessary GROUP BY.
Add uid into ORDER BY so that messages are enumerated
mostly in the order of insertions, which potentially reduces
chances that messages will be reordered later.

* SQLDict_readMessage.zsql

Use DISTINCT and GROUP BY, only if necessary.
Add uid into ORDER BY for the same reason as above.

* SQLDict_createMessageTable.zsql

Specify NOT NULL whenever possible to reduce data size.
Use SMALLINT instead of INT for processing_node to reduce data size.
Remove useless indexes to reduce the cost of UPDATE.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13582 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent da611485
...@@ -17,11 +17,13 @@ SET ...@@ -17,11 +17,13 @@ SET
processing_node=<dtml-sqlvar processing_node type="int">, processing_node=<dtml-sqlvar processing_node type="int">,
processing=0 processing=0
WHERE WHERE
processing_node = -1
<dtml-if uid> <dtml-if uid>
<dtml-in uid>uid = <dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> AND uid IN (
OR </dtml-if></dtml-in> <dtml-in uid><dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>
)
<dtml-else> <dtml-else>
path = <dtml-sqlvar path type="string"> AND path = <dtml-sqlvar path type="string">
<dtml-if method_id>AND method_id = <dtml-sqlvar method_id type="string"></dtml-if> <dtml-if method_id>AND method_id = <dtml-sqlvar method_id type="string"></dtml-if>
</dtml-if> </dtml-if>
<dtml-if broadcast> <dtml-if broadcast>
......
...@@ -9,28 +9,26 @@ class_file: ...@@ -9,28 +9,26 @@ class_file:
</dtml-comment> </dtml-comment>
<params></params> <params></params>
CREATE TABLE `message` ( CREATE TABLE `message` (
`uid` INT UNSIGNED NOT NULL auto_increment, `uid` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`date` datetime, `date` DATETIME NOT NULL,
`path` VARCHAR(255), `path` VARCHAR(255) NOT NULL,
`method_id` VARCHAR(255), `method_id` VARCHAR(255) NOT NULL,
`processing_node` INT DEFAULT -1, `processing_node` SMALLINT NOT NULL DEFAULT -1,
`processing` TINYINT DEFAULT 0, `processing` TINYINT NOT NULL DEFAULT 0,
`processing_date` datetime, `processing_date` DATETIME,
`priority` TINYINT DEFAULT 0, `priority` TINYINT NOT NULL DEFAULT 0,
`broadcast` TINYINT DEFAULT 0, `broadcast` TINYINT NOT NULL DEFAULT 0,
`group_method_id` VARCHAR(255) DEFAULT '', `group_method_id` VARCHAR(255) NOT NULL DEFAULT '',
`tag` VARCHAR(255), `tag` VARCHAR(255) NOT NULL,
`retry` TINYINT UNSIGNED NOT NULL DEFAULT 0, `retry` TINYINT UNSIGNED NOT NULL DEFAULT 0,
`order_validation_text` VARCHAR(255), `order_validation_text` VARCHAR(255) NOT NULL,
`message` BLOB, `message` BLOB NOT NULL,
PRIMARY KEY (`uid`), PRIMARY KEY (`uid`),
KEY `date` (`date`), KEY (`path`),
KEY `path` (`path`), KEY (`method_id`),
KEY `method_id` (`method_id`), KEY (`processing_node`),
KEY `processing_node` (`processing_node`), KEY (`processing`),
KEY `processing` (`processing`), KEY (`priority`),
KEY `processing_date` (`processing_date`), KEY (`tag`),
KEY `priority` (`priority`), KEY (`order_validation_text`)
KEY `tag` (`tag`),
KEY `order_validation_text` (`order_validation_text`)
) TYPE = InnoDB; ) TYPE = InnoDB;
...@@ -13,7 +13,7 @@ to_date ...@@ -13,7 +13,7 @@ to_date
to_processing_date to_processing_date
group_method_id group_method_id
order_validation_text</params> order_validation_text</params>
SELECT DISTINCT * FROM SELECT <dtml-if group_method_id>DISTINCT</dtml-if> * FROM
message message
WHERE WHERE
processing <> 1 processing <> 1
...@@ -22,11 +22,12 @@ WHERE ...@@ -22,11 +22,12 @@ WHERE
<dtml-if to_date>AND date <= <dtml-sqlvar to_date type="datetime"> </dtml-if> <dtml-if to_date>AND date <= <dtml-sqlvar to_date type="datetime"> </dtml-if>
<dtml-if group_method_id>AND group_method_id = <dtml-sqlvar group_method_id type="string"> </dtml-if> <dtml-if group_method_id>AND group_method_id = <dtml-sqlvar group_method_id type="string"> </dtml-if>
<dtml-if order_validation_text>AND order_validation_text = <dtml-sqlvar order_validation_text type="string"> </dtml-if> <dtml-if order_validation_text>AND order_validation_text = <dtml-sqlvar order_validation_text type="string"> </dtml-if>
<dtml-if group_method_id>
GROUP BY GROUP BY
path, method_id path, method_id
</dtml-if>
ORDER BY ORDER BY
priority, date priority, date, uid
<dtml-if group_method_id> <dtml-if group_method_id>
LIMIT 100 LIMIT 100
<dtml-else> <dtml-else>
......
...@@ -34,7 +34,5 @@ WHERE ...@@ -34,7 +34,5 @@ WHERE
<dtml-if priority> AND priority = <dtml-sqlvar priority type="int"> </dtml-if> <dtml-if priority> AND priority = <dtml-sqlvar priority type="int"> </dtml-if>
<dtml-if path>AND path = <dtml-sqlvar path type="string"> </dtml-if> <dtml-if path>AND path = <dtml-sqlvar path type="string"> </dtml-if>
<dtml-if method_id> AND method_id = <dtml-sqlvar method_id type="string"> </dtml-if> <dtml-if method_id> AND method_id = <dtml-sqlvar method_id type="string"> </dtml-if>
GROUP BY
path, method_id, tag, processing_node, processing
ORDER BY ORDER BY
priority, date priority, date, uid
...@@ -32,10 +32,8 @@ SET ...@@ -32,10 +32,8 @@ SET
WHERE WHERE
1 = 1 1 = 1
<dtml-if uid> <dtml-if uid>
AND ( AND uid IN (
<dtml-in uid> <dtml-in uid><dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>
uid = <dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>
</dtml-in>
) )
</dtml-if> </dtml-if>
<dtml-if processing_node> <dtml-if processing_node>
...@@ -43,4 +41,4 @@ WHERE ...@@ -43,4 +41,4 @@ WHERE
</dtml-if> </dtml-if>
<dtml-if order_validation_text> <dtml-if order_validation_text>
AND order_validation_text = <dtml-sqlvar order_validation_text type="string"> AND order_validation_text = <dtml-sqlvar order_validation_text type="string">
</dtml-if> </dtml-if>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment