Skip to content

Commit

Permalink
Add index on the pua table for peformance reasons.
Browse files Browse the repository at this point in the history
Credits go to "lirakin" on IRC
  • Loading branch information
bogdan-iancu committed Jul 1, 2014
1 parent f80f9fc commit 59061f1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
29 changes: 24 additions & 5 deletions db/schema/pr_pua.xml
Expand Up @@ -26,30 +26,30 @@
<description>Unique ID</description>
</column>

<column>
<column id="pres_uri">
<name>pres_uri</name>
<type>string</type>
<size>&uri_len;</size>
<description>URI</description>
<natural/>
</column>

<column>
<column id="pres_id">
<name>pres_id</name>
<type>string</type>
<size>255</size>
<description>ID</description>
</column>

<column>
<column id="event">
<name>event</name>
<type>int</type>
<size>11</size>
<description>Event</description>
<natural/>
</column>

<column>
<column id="expires">
<name>expires</name>
<type>int</type>
<size>&expires_len;</size>
Expand All @@ -63,7 +63,7 @@
<description>Desired Expires</description>
</column>

<column>
<column id="flag">
<name>flag</name>
<type>int</type>
<size>&flag_len;</size>
Expand Down Expand Up @@ -170,4 +170,23 @@
<description>Extra Headers</description>
</column>

<index>
<name>del1_idx</name>
<colref linkend="pres_uri"/>
<colref linkend="event"/>
</index>

<index>
<name>del2_idx</name>
<colref linkend="expires"/>
</index>

<index>
<name>update_idx</name>
<colref linkend="pres_uri"/>
<colref linkend="pres_id"/>
<colref linkend="flag"/>
<colref linkend="event"/>
</index>

</table>
12 changes: 6 additions & 6 deletions modules/pua/hash.c
Expand Up @@ -430,6 +430,12 @@ static void pua_db_delete(ua_pres_t* pres)
vals[n_query_cols].val.str_val = *pres->pres_uri;
n_query_cols++;

cols[n_query_cols] = &str_event_col;
vals[n_query_cols].type = DB_INT;
vals[n_query_cols].nul = 0;
vals[n_query_cols].val.int_val = pres->event;
n_query_cols++;

if(pres->flag)
{
cols[n_query_cols] = &str_flag_col;
Expand All @@ -439,12 +445,6 @@ static void pua_db_delete(ua_pres_t* pres)
n_query_cols++;
}

cols[n_query_cols] = &str_event_col;
vals[n_query_cols].type = DB_INT;
vals[n_query_cols].nul = 0;
vals[n_query_cols].val.int_val = pres->event;
n_query_cols++;

if(pres->id.s && pres->id.len)
{
cols[n_query_cols] = &str_pres_id_col;
Expand Down
4 changes: 4 additions & 0 deletions scripts/mysql/presence-create.sql
Expand Up @@ -92,3 +92,7 @@ CREATE TABLE pua (
extra_headers TEXT
) ENGINE=MyISAM;

CREATE INDEX del1_idx ON pua (pres_uri, event);
CREATE INDEX del2_idx ON pua (expires);
CREATE INDEX update_idx ON pua (pres_uri, pres_id, flag, event);

4 changes: 4 additions & 0 deletions scripts/oracle/presence-create.sql
Expand Up @@ -132,3 +132,7 @@ END pua_tr;
/
BEGIN map2users('pua'); END;
/
CREATE INDEX pua_del1_idx ON pua (pres_uri, event);
CREATE INDEX pua_del2_idx ON pua (expires);
CREATE INDEX pua_update_idx ON pua (pres_uri, pres_id, flag, event);

4 changes: 4 additions & 0 deletions scripts/postgres/presence-create.sql
Expand Up @@ -97,3 +97,7 @@ CREATE TABLE pua (
);

ALTER SEQUENCE pua_id_seq MAXVALUE 2147483647 CYCLE;
CREATE INDEX pua_del1_idx ON pua (pres_uri, event);
CREATE INDEX pua_del2_idx ON pua (expires);
CREATE INDEX pua_update_idx ON pua (pres_uri, pres_id, flag, event);

0 comments on commit 59061f1

Please sign in to comment.