<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[iRedMail — way to long running query when loging in.]]></title>
		<link>https://forum.iredmail.org/topic20083-way-to-long-running-query-when-loging-in.html</link>
		<atom:link href="https://forum.iredmail.org/feed-rss-topic20083.xml" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in way to long running query when loging in..]]></description>
		<lastBuildDate>Mon, 23 Oct 2023 05:35:07 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: way to long running query when loging in.]]></title>
			<link>https://forum.iredmail.org/post87522.html#p87522</link>
			<description><![CDATA[<div class="quotebox"><cite>mediatis wrote:</cite><blockquote><p>Hi, sorry I missed that one. The output is:</p></blockquote></div><p>Indexes seem fine, but i found the output of SQL command offered by @Cthulhu is not ideal:<br /></p><div class="codebox"><pre><code>MariaDB [amavisd]&gt; explain SELECT COUNT(msgs.mail_id) AS total FROM msgs LEFT JOIN msgrcpt ON (msgs.mail_id = msgrcpt.mail_id) LEFT JOIN maddr AS sender ON (msgs.sid = sender.id) LEFT JOIN maddr AS recip ON (msgrcpt.rid = recip.id) WHERE msgs.quar_type &lt;&gt; &#039;Q&#039;; 
+------+-------------+---------+------+---------------------+---------------------+---------+----------------------+------+-------------+
| id   | select_type | table   | type | possible_keys       | key                 | key_len | ref                  | rows | Extra       |
+------+-------------+---------+------+---------------------+---------------------+---------+----------------------+------+-------------+
|    1 | SIMPLE      | msgs    | ALL  | msgs_idx_quar_type  | NULL                | NULL    | NULL                 | 7361 | Using where |
|    1 | SIMPLE      | msgrcpt | ref  | msgrcpt_idx_mail_id | msgrcpt_idx_mail_id | 18      | amavisd.msgs.mail_id |    1 |             |
+------+-------------+---------+------+---------------------+---------------------+---------+----------------------+------+-------------+
2 rows in set (0.001 sec)</code></pre></div><p>Same command in different output format:<br /></p><div class="codebox"><pre><code>*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: msgs
         type: ALL
possible_keys: msgs_idx_quar_type
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 7361
        Extra: Using where
*************************** 2. row ***************************
           id: 1
  select_type: SIMPLE
        table: msgrcpt
         type: ref
possible_keys: msgrcpt_idx_mail_id
          key: msgrcpt_idx_mail_id
      key_len: 18
          ref: amavisd.msgs.mail_id
         rows: 1
        Extra: 
2 rows in set (0.001 sec)</code></pre></div><p>It says &quot;possible_keys: msgs_idx_quar_type&quot;, but &quot;key: NULL&quot;, seems index `msgs_idx_quar_type` is not used at all.</p>]]></description>
			<author><![CDATA[null@example.com (ZhangHuangbin)]]></author>
			<pubDate>Mon, 23 Oct 2023 05:35:07 +0000</pubDate>
			<guid>https://forum.iredmail.org/post87522.html#p87522</guid>
		</item>
		<item>
			<title><![CDATA[Re: way to long running query when loging in.]]></title>
			<link>https://forum.iredmail.org/post87469.html#p87469</link>
			<description><![CDATA[<div class="quotebox"><cite>ZhangHuangbin wrote:</cite><blockquote><div class="quotebox"><cite>mediatis wrote:</cite><blockquote><p>the indexes seem to be fitting.</p></blockquote></div><p>What&#039;s the command output mentioned in my previous reply?</p></blockquote></div><p>Hi, sorry I missed that one. The output is:<br /></p><div class="codebox"><pre><code>MariaDB [amavisd]&gt; SHOW INDEX FROM msgs;
+-------+------------+---------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| Table | Non_unique | Key_name                  | Seq_in_index | Column_name   | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Ignored |
+-------+------------+---------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| msgs  |          0 | PRIMARY                   |            1 | partition_tag | A         |           2 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| msgs  |          0 | PRIMARY                   |            2 | mail_id       | A         |      391126 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| msgs  |          1 | msgs_idx_sid              |            1 | sid           | A         |      195563 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| msgs  |          1 | msgs_idx_mess_id          |            1 | message_id    | A         |      391126 |     NULL | NULL   | YES  | BTREE      |         |               | NO      |
| msgs  |          1 | msgs_idx_time_num         |            1 | time_num      | A         |      391126 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| msgs  |          1 | msgs_idx_mail_id          |            1 | mail_id       | A         |      391126 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| msgs  |          1 | msgs_idx_content          |            1 | content       | A         |          14 |     NULL | NULL   | YES  | BTREE      |         |               | NO      |
| msgs  |          1 | msgs_idx_quar_type        |            1 | quar_type     | A         |           4 |     NULL | NULL   | YES  | BTREE      |         |               | NO      |
| msgs  |          1 | msgs_idx_content_time_num |            1 | content       | A         |          14 |     NULL | NULL   | YES  | BTREE      |         |               | NO      |
| msgs  |          1 | msgs_idx_content_time_num |            2 | time_num      | A         |      391126 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| msgs  |          1 | msgs_idx_spam_level       |            1 | spam_level    | A         |       30086 |     NULL | NULL   | YES  | BTREE      |         |               | NO      |
+-------+------------+---------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
11 rows in set (0.000 sec)

MariaDB [amavisd]&gt; SHOW INDEX FROM msgrcpt;
+---------+------------+---------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| Table   | Non_unique | Key_name            | Seq_in_index | Column_name   | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Ignored |
+---------+------------+---------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| msgrcpt |          0 | PRIMARY             |            1 | partition_tag | A         |           2 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| msgrcpt |          0 | PRIMARY             |            2 | mail_id       | A         |      311379 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| msgrcpt |          0 | PRIMARY             |            3 | rseqnum       | A         |      311379 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| msgrcpt |          1 | msgrcpt_idx_mail_id |            1 | mail_id       | A         |      311379 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| msgrcpt |          1 | msgrcpt_idx_rid     |            1 | rid           | A         |       44482 |     NULL | NULL   |      | BTREE      |         |               | NO      |
+---------+------------+---------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
5 rows in set (0.000 sec)

MariaDB [amavisd]&gt; SHOW INDEX FROM quarantine;
+------------+------------+------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| Table      | Non_unique | Key_name         | Seq_in_index | Column_name   | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Ignored |
+------------+------------+------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| quarantine |          0 | PRIMARY          |            1 | partition_tag | A         |           2 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| quarantine |          0 | PRIMARY          |            2 | mail_id       | A         |          58 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| quarantine |          0 | PRIMARY          |            3 | chunk_ind     | A         |         176 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| quarantine |          1 | quar_idx_mail_id |            1 | mail_id       | A         |          58 |     NULL | NULL   |      | BTREE      |         |               | NO      |
+------------+------------+------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
4 rows in set (0.000 sec)</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (mediatis)]]></author>
			<pubDate>Thu, 12 Oct 2023 08:45:14 +0000</pubDate>
			<guid>https://forum.iredmail.org/post87469.html#p87469</guid>
		</item>
		<item>
			<title><![CDATA[Re: way to long running query when loging in.]]></title>
			<link>https://forum.iredmail.org/post87464.html#p87464</link>
			<description><![CDATA[<div class="quotebox"><cite>mediatis wrote:</cite><blockquote><p>the indexes seem to be fitting.</p></blockquote></div><p>What&#039;s the command output mentioned in my previous reply?</p>]]></description>
			<author><![CDATA[null@example.com (ZhangHuangbin)]]></author>
			<pubDate>Wed, 11 Oct 2023 14:35:08 +0000</pubDate>
			<guid>https://forum.iredmail.org/post87464.html#p87464</guid>
		</item>
		<item>
			<title><![CDATA[Re: way to long running query when loging in.]]></title>
			<link>https://forum.iredmail.org/post87461.html#p87461</link>
			<description><![CDATA[<div class="quotebox"><cite>ZhangHuangbin wrote:</cite><blockquote><p>- each column used in query is indexed separately, although no composite index, but it should be still fast enough.<br />- How many records in each table: msgs, msgrcpt, quarantine?<br />- Please show us your indexes, and compare them with the ones created by iRedMail: <a href="https://github.com/iredmail/iRedMail/blob/master/samples/amavisd/amavisd.mysql">https://github.com/iredmail/iRedMail/bl … visd.mysql</a></p><div class="codebox"><pre><code>SHOW INDEX FROM msgs;
SHOW INDEX FROM msgrcpt;
SHOW INDEX FROM quarantine;</code></pre></div></blockquote></div><p>the indexes seem to be fitting.<br />Records in:<br />msgs:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 407995<br />msgrcpt:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;407950<br />quarantine:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 189</p>]]></description>
			<author><![CDATA[null@example.com (mediatis)]]></author>
			<pubDate>Wed, 11 Oct 2023 07:09:37 +0000</pubDate>
			<guid>https://forum.iredmail.org/post87461.html#p87461</guid>
		</item>
		<item>
			<title><![CDATA[Re: way to long running query when loging in.]]></title>
			<link>https://forum.iredmail.org/post87460.html#p87460</link>
			<description><![CDATA[<div class="quotebox"><cite>Cthulhu wrote:</cite><blockquote><p>this seems more a problem with the mariadb database, the SQL query should not take that long</p><p>how many domains?</p><p>you can:<br />empty tables msgs, madrr, msrcpt</p><p>this doesn&#039;t brick anthing, you just cannot see infos about send and recived mails in admin interface anymore</p><p>my best guess is, that you are missing indexes on your database and this wasn&#039;t a new installation, but an update</p></blockquote></div><p>yep it was an upgrade and always kept up to date. the last two years, while before was not really cared about...</p>]]></description>
			<author><![CDATA[null@example.com (mediatis)]]></author>
			<pubDate>Wed, 11 Oct 2023 07:06:01 +0000</pubDate>
			<guid>https://forum.iredmail.org/post87460.html#p87460</guid>
		</item>
		<item>
			<title><![CDATA[Re: way to long running query when loging in.]]></title>
			<link>https://forum.iredmail.org/post87459.html#p87459</link>
			<description><![CDATA[<div class="quotebox"><cite>Cthulhu wrote:</cite><blockquote><p>could you pls run this statement and tell me the results:</p><div class="codebox"><pre><code>SELECT COUNT(msgs.mail_id) AS total
FROM msgs
LEFT JOIN msgrcpt ON (msgs.mail_id = msgrcpt.mail_id)
LEFT JOIN maddr AS sender ON (msgs.sid = sender.id)
LEFT JOIN maddr AS recip ON (msgrcpt.rid = recip.id)
WHERE msgs.quar_type &lt;&gt; &#039;Q&#039;;</code></pre></div><p>i only need the total runtime of the statement</p></blockquote></div><p>Runtime here is: 1 row in set (13.307 sec)</p>]]></description>
			<author><![CDATA[null@example.com (mediatis)]]></author>
			<pubDate>Wed, 11 Oct 2023 07:04:54 +0000</pubDate>
			<guid>https://forum.iredmail.org/post87459.html#p87459</guid>
		</item>
		<item>
			<title><![CDATA[Re: way to long running query when loging in.]]></title>
			<link>https://forum.iredmail.org/post87458.html#p87458</link>
			<description><![CDATA[<p>- each column used in query is indexed separately, although no composite index, but it should be still fast enough.<br />- How many records in each table: msgs, msgrcpt, quarantine?<br />- Please show us your indexes, and compare them with the ones created by iRedMail: <a href="https://github.com/iredmail/iRedMail/blob/master/samples/amavisd/amavisd.mysql">https://github.com/iredmail/iRedMail/bl … visd.mysql</a></p><div class="codebox"><pre><code>SHOW INDEX FROM msgs;
SHOW INDEX FROM msgrcpt;
SHOW INDEX FROM quarantine;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (ZhangHuangbin)]]></author>
			<pubDate>Wed, 11 Oct 2023 05:33:07 +0000</pubDate>
			<guid>https://forum.iredmail.org/post87458.html#p87458</guid>
		</item>
		<item>
			<title><![CDATA[Re: way to long running query when loging in.]]></title>
			<link>https://forum.iredmail.org/post87452.html#p87452</link>
			<description><![CDATA[<p>could you pls run this statement and tell me the results:</p><div class="codebox"><pre><code>SELECT COUNT(msgs.mail_id) AS total
FROM msgs
LEFT JOIN msgrcpt ON (msgs.mail_id = msgrcpt.mail_id)
LEFT JOIN maddr AS sender ON (msgs.sid = sender.id)
LEFT JOIN maddr AS recip ON (msgrcpt.rid = recip.id)
WHERE msgs.quar_type &lt;&gt; &#039;Q&#039;;</code></pre></div><p>i only need the total runtime of the statement</p>]]></description>
			<author><![CDATA[null@example.com (Cthulhu)]]></author>
			<pubDate>Tue, 10 Oct 2023 15:16:50 +0000</pubDate>
			<guid>https://forum.iredmail.org/post87452.html#p87452</guid>
		</item>
		<item>
			<title><![CDATA[Re: way to long running query when loging in.]]></title>
			<link>https://forum.iredmail.org/post87451.html#p87451</link>
			<description><![CDATA[<p>this seems more a problem with the mariadb database, the SQL query should not take that long</p><p>how many domains?</p><p>you can:<br />empty tables msgs, madrr, msrcpt</p><p>this doesn&#039;t brick anthing, you just cannot see infos about send and recived mails in admin interface anymore</p><p>my best guess is, that you are missing indexes on your database and this wasn&#039;t a new installation, but an update</p>]]></description>
			<author><![CDATA[null@example.com (Cthulhu)]]></author>
			<pubDate>Tue, 10 Oct 2023 14:57:47 +0000</pubDate>
			<guid>https://forum.iredmail.org/post87451.html#p87451</guid>
		</item>
		<item>
			<title><![CDATA[way to long running query when loging in.]]></title>
			<link>https://forum.iredmail.org/post87450.html#p87450</link>
			<description><![CDATA[<p>==== REQUIRED BASIC INFO OF YOUR IREDMAIL SERVER ====<br />- iRedMail version (check /etc/iredmail-release): 1.6.5 OPENLDAP edition<br />- Deployed with iRedMail Easy or the downloadable installer? downloadable installer<br />- Linux/BSD distribution name and version: Ubuntu 22.04 LTS<br />- Store mail accounts in which backend (LDAP/MySQL/PGSQL): LDAP<br />- Web server (Apache or Nginx): Nginx<br />- Manage mail accounts with iRedAdmin-Pro? Yes<br />- [IMPORTANT] Related original log or error message is required if you&#039;re experiencing an issue.<br />====</p><p>We are having trouble with logins to iRedAdmin-Pro, a longrunning SQL querry runs into an timeout.</p><p>Responsible Querry:<br /></p><div class="codebox"><pre><code>MariaDB [amavisd]&gt; SELECT COUNT(msgs.mail_id) AS total
    -&gt;                         FROM msgs
    -&gt;                         LEFT JOIN msgrcpt ON (msgs.mail_id = msgrcpt.mail_id)
    -&gt;                         LEFT JOIN maddr AS sender ON (msgs.sid = sender.id)
    -&gt;                         LEFT JOIN maddr AS recip ON (msgrcpt.rid = recip.id)
    -&gt;                         WHERE msgs.quar_type &lt;&gt; &#039;Q&#039;  AND recip.domain IN (&#039;&lt;LIST OF DOMAINS&gt;&#039;) AND msgs.time_num &gt; 1696837022
    -&gt; ;
+-------+
| total |
+-------+
|  3419 |
+-------+
1 row in set (47.928 sec)</code></pre></div><p>we for now did a workaround by adding an uwsgi timeout to the nginx config:</p><p>/etc/nginx/templates/iredadmin.tmpl <br /></p><div class="codebox"><pre><code>uwsgi_param SCRIPT_NAME /iredadmin;
uwsgi_read_timeout 600s;

# Access control</code></pre></div><p>As this is for us only a workaround, we would like to know how we could fix it.</p>]]></description>
			<author><![CDATA[null@example.com (mediatis)]]></author>
			<pubDate>Tue, 10 Oct 2023 10:17:24 +0000</pubDate>
			<guid>https://forum.iredmail.org/post87450.html#p87450</guid>
		</item>
	</channel>
</rss>
