Advice on fine-tuning query and index for performanceUnexplained InnoDB timeoutsAre two indexes needed?Adding...

What can I do to encourage my players to use their consumables?

Identical projects by students at two different colleges: still plagiarism?

Probability X1 ≥ X2

How do I fight with Heavy Armor as a Wizard with Tenser's Transformation?

Taking an academic pseudonym?

Why write a book when there's a movie in my head?

Dealing with an internal ScriptKiddie

Are there historical references that show that "diatonic" is a version of 'di-tonic' meaning 'two tonics'?

How can I put a period right after the algorithm's number in the algorithm's title?

Calculating the strength of an ionic bond that contains poly-atomic ions

Sing Baby Shark

Why don't you get burned by the wood benches in a sauna?

Is "accuse people to be racist" grammatical?

Is there a way to pause a running process on Linux systems and resume later?

Isn't a semicolon (';') needed after a function declaration in C++?

Is it possible to narrate a novel in a faux-historical style without alienating the reader?

Is there any danger of my neighbor having my wife's signature?

What if I miss a connection and don't have money to book next flight?

Why did Ylvis use "go" instead of "say" in phrases like "Dog goes 'woof'"?

How bad is a Computer Science course that doesn't teach Design Patterns?

How to know if I am a 'Real Developer'

Intersection of 3 planes in 3D space

Is it really OK to use "because of"?

Why is it that Bernie Sanders is always called a "socialist"?



Advice on fine-tuning query and index for performance


Unexplained InnoDB timeoutsAre two indexes needed?Adding index to large mysql tablesSimple query is slow on 4M-rows tableOptimizing a simple query on a large tableHow to improve query count execution with mySql replicate?MySQL query taking too longMySQLDump issue with a special charactersconvert default charset utf8 tables to utf8mb4 mysql 5.7.17select MAX() from MySQL view (2x INNER JOIN) is slow













1















Currently my query is as below:



select id_request,username_request
from darkhast_follower
where darkhast_follower.id_request != '9762952594'
AND darkhast_follower.status =0
AND NOT exists ( select null
from log_follow
where log_follow.other_id = darkhast_follower.id_request
AND log_follow.id= '9762952594' LIMIT 1)
LIMIT 1


Table log_follow has 30 milion rows and darkhast_follower has 1000 rows respectively.



log_follow is indexed on column (other_id) and (id), darkhast_follower is indexed on column (id_request) and (status).



The performance seems to be slow and looking for expert advice on fine-tuning the query and index suggestion. Currently I have 40k active users.



-- Server version: 5.7.23-log
-- PHP Version: 5.6.31

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;


-- --------------------------------------------------------

--
-- Table structure for table `darkhast_follower`
--

CREATE TABLE `darkhast_follower` (
`IDD` int(11) NOT NULL,
`id` varchar(20) NOT NULL,
`username` varchar(65) NOT NULL,
`id_request` varchar(20) NOT NULL,
`username_request` varchar(65) NOT NULL,
`token_id` text NOT NULL,
`darkhasti` int(5) NOT NULL,
`daryafti` int(5) NOT NULL,
`date` text NOT NULL,
`status` tinyint(1) NOT NULL,
`gsm_sender` tinyint(1) NOT NULL,
`error_report` tinyint(3) NOT NULL,
`bot` tinyint(1) NOT NULL,
`back` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `darkhast_follower`
--
ALTER TABLE `darkhast_follower`
ADD PRIMARY KEY (`IDD`),
ADD KEY `status` (`status`),
ADD KEY `id_request` (`id_request`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `darkhast_follower`
--
ALTER TABLE `darkhast_follower`
MODIFY `IDD` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

-- --------------------------------------------------------

--
-- Table structure for table `log_follow`
--

CREATE TABLE `log_follow` (
`IDD` int(11) NOT NULL,
`id` varchar(20) NOT NULL,
`username` varchar(65) NOT NULL,
`other_user` varchar(65) NOT NULL,
`other_id` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `log_follow`
--
ALTER TABLE `log_follow`
ADD PRIMARY KEY (`IDD`),
ADD KEY `id` (`id`),
ADD KEY `other_id` (`other_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `log_follow`
--
ALTER TABLE `log_follow`
MODIFY `IDD` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


darkhast_followerlog_follow










share|improve this question




















  • 1





    Welcome to DBA.SE! Could you post the DDL for these tables & indexes please? DDL is always better than images as it helps us recreate the issue you are having. Thanks!

    – Mr.Brownstone
    4 hours ago











  • @Mr.Brownstone What is DDL?

    – Marvan Eimaz
    4 hours ago











  • DDL stands for Data Definition Language. Essentially, the CREATE TABLE & CREATE INDEX statements.

    – Mr.Brownstone
    4 hours ago






  • 1





    @Mr.Brownstone added

    – Marvan Eimaz
    4 hours ago











  • Please add the output of EXPLAIN SELECT ... for your query.

    – ypercubeᵀᴹ
    14 mins ago
















1















Currently my query is as below:



select id_request,username_request
from darkhast_follower
where darkhast_follower.id_request != '9762952594'
AND darkhast_follower.status =0
AND NOT exists ( select null
from log_follow
where log_follow.other_id = darkhast_follower.id_request
AND log_follow.id= '9762952594' LIMIT 1)
LIMIT 1


Table log_follow has 30 milion rows and darkhast_follower has 1000 rows respectively.



log_follow is indexed on column (other_id) and (id), darkhast_follower is indexed on column (id_request) and (status).



The performance seems to be slow and looking for expert advice on fine-tuning the query and index suggestion. Currently I have 40k active users.



-- Server version: 5.7.23-log
-- PHP Version: 5.6.31

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;


-- --------------------------------------------------------

--
-- Table structure for table `darkhast_follower`
--

CREATE TABLE `darkhast_follower` (
`IDD` int(11) NOT NULL,
`id` varchar(20) NOT NULL,
`username` varchar(65) NOT NULL,
`id_request` varchar(20) NOT NULL,
`username_request` varchar(65) NOT NULL,
`token_id` text NOT NULL,
`darkhasti` int(5) NOT NULL,
`daryafti` int(5) NOT NULL,
`date` text NOT NULL,
`status` tinyint(1) NOT NULL,
`gsm_sender` tinyint(1) NOT NULL,
`error_report` tinyint(3) NOT NULL,
`bot` tinyint(1) NOT NULL,
`back` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `darkhast_follower`
--
ALTER TABLE `darkhast_follower`
ADD PRIMARY KEY (`IDD`),
ADD KEY `status` (`status`),
ADD KEY `id_request` (`id_request`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `darkhast_follower`
--
ALTER TABLE `darkhast_follower`
MODIFY `IDD` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

-- --------------------------------------------------------

--
-- Table structure for table `log_follow`
--

CREATE TABLE `log_follow` (
`IDD` int(11) NOT NULL,
`id` varchar(20) NOT NULL,
`username` varchar(65) NOT NULL,
`other_user` varchar(65) NOT NULL,
`other_id` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `log_follow`
--
ALTER TABLE `log_follow`
ADD PRIMARY KEY (`IDD`),
ADD KEY `id` (`id`),
ADD KEY `other_id` (`other_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `log_follow`
--
ALTER TABLE `log_follow`
MODIFY `IDD` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


darkhast_followerlog_follow










share|improve this question




















  • 1





    Welcome to DBA.SE! Could you post the DDL for these tables & indexes please? DDL is always better than images as it helps us recreate the issue you are having. Thanks!

    – Mr.Brownstone
    4 hours ago











  • @Mr.Brownstone What is DDL?

    – Marvan Eimaz
    4 hours ago











  • DDL stands for Data Definition Language. Essentially, the CREATE TABLE & CREATE INDEX statements.

    – Mr.Brownstone
    4 hours ago






  • 1





    @Mr.Brownstone added

    – Marvan Eimaz
    4 hours ago











  • Please add the output of EXPLAIN SELECT ... for your query.

    – ypercubeᵀᴹ
    14 mins ago














1












1








1








Currently my query is as below:



select id_request,username_request
from darkhast_follower
where darkhast_follower.id_request != '9762952594'
AND darkhast_follower.status =0
AND NOT exists ( select null
from log_follow
where log_follow.other_id = darkhast_follower.id_request
AND log_follow.id= '9762952594' LIMIT 1)
LIMIT 1


Table log_follow has 30 milion rows and darkhast_follower has 1000 rows respectively.



log_follow is indexed on column (other_id) and (id), darkhast_follower is indexed on column (id_request) and (status).



The performance seems to be slow and looking for expert advice on fine-tuning the query and index suggestion. Currently I have 40k active users.



-- Server version: 5.7.23-log
-- PHP Version: 5.6.31

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;


-- --------------------------------------------------------

--
-- Table structure for table `darkhast_follower`
--

CREATE TABLE `darkhast_follower` (
`IDD` int(11) NOT NULL,
`id` varchar(20) NOT NULL,
`username` varchar(65) NOT NULL,
`id_request` varchar(20) NOT NULL,
`username_request` varchar(65) NOT NULL,
`token_id` text NOT NULL,
`darkhasti` int(5) NOT NULL,
`daryafti` int(5) NOT NULL,
`date` text NOT NULL,
`status` tinyint(1) NOT NULL,
`gsm_sender` tinyint(1) NOT NULL,
`error_report` tinyint(3) NOT NULL,
`bot` tinyint(1) NOT NULL,
`back` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `darkhast_follower`
--
ALTER TABLE `darkhast_follower`
ADD PRIMARY KEY (`IDD`),
ADD KEY `status` (`status`),
ADD KEY `id_request` (`id_request`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `darkhast_follower`
--
ALTER TABLE `darkhast_follower`
MODIFY `IDD` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

-- --------------------------------------------------------

--
-- Table structure for table `log_follow`
--

CREATE TABLE `log_follow` (
`IDD` int(11) NOT NULL,
`id` varchar(20) NOT NULL,
`username` varchar(65) NOT NULL,
`other_user` varchar(65) NOT NULL,
`other_id` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `log_follow`
--
ALTER TABLE `log_follow`
ADD PRIMARY KEY (`IDD`),
ADD KEY `id` (`id`),
ADD KEY `other_id` (`other_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `log_follow`
--
ALTER TABLE `log_follow`
MODIFY `IDD` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


darkhast_followerlog_follow










share|improve this question
















Currently my query is as below:



select id_request,username_request
from darkhast_follower
where darkhast_follower.id_request != '9762952594'
AND darkhast_follower.status =0
AND NOT exists ( select null
from log_follow
where log_follow.other_id = darkhast_follower.id_request
AND log_follow.id= '9762952594' LIMIT 1)
LIMIT 1


Table log_follow has 30 milion rows and darkhast_follower has 1000 rows respectively.



log_follow is indexed on column (other_id) and (id), darkhast_follower is indexed on column (id_request) and (status).



The performance seems to be slow and looking for expert advice on fine-tuning the query and index suggestion. Currently I have 40k active users.



-- Server version: 5.7.23-log
-- PHP Version: 5.6.31

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;


-- --------------------------------------------------------

--
-- Table structure for table `darkhast_follower`
--

CREATE TABLE `darkhast_follower` (
`IDD` int(11) NOT NULL,
`id` varchar(20) NOT NULL,
`username` varchar(65) NOT NULL,
`id_request` varchar(20) NOT NULL,
`username_request` varchar(65) NOT NULL,
`token_id` text NOT NULL,
`darkhasti` int(5) NOT NULL,
`daryafti` int(5) NOT NULL,
`date` text NOT NULL,
`status` tinyint(1) NOT NULL,
`gsm_sender` tinyint(1) NOT NULL,
`error_report` tinyint(3) NOT NULL,
`bot` tinyint(1) NOT NULL,
`back` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `darkhast_follower`
--
ALTER TABLE `darkhast_follower`
ADD PRIMARY KEY (`IDD`),
ADD KEY `status` (`status`),
ADD KEY `id_request` (`id_request`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `darkhast_follower`
--
ALTER TABLE `darkhast_follower`
MODIFY `IDD` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

-- --------------------------------------------------------

--
-- Table structure for table `log_follow`
--

CREATE TABLE `log_follow` (
`IDD` int(11) NOT NULL,
`id` varchar(20) NOT NULL,
`username` varchar(65) NOT NULL,
`other_user` varchar(65) NOT NULL,
`other_id` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `log_follow`
--
ALTER TABLE `log_follow`
ADD PRIMARY KEY (`IDD`),
ADD KEY `id` (`id`),
ADD KEY `other_id` (`other_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `log_follow`
--
ALTER TABLE `log_follow`
MODIFY `IDD` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


darkhast_followerlog_follow







mysql query-performance optimization index-tuning






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 7 mins ago









ypercubeᵀᴹ

76.9k11134214




76.9k11134214










asked 4 hours ago









Marvan EimazMarvan Eimaz

62




62








  • 1





    Welcome to DBA.SE! Could you post the DDL for these tables & indexes please? DDL is always better than images as it helps us recreate the issue you are having. Thanks!

    – Mr.Brownstone
    4 hours ago











  • @Mr.Brownstone What is DDL?

    – Marvan Eimaz
    4 hours ago











  • DDL stands for Data Definition Language. Essentially, the CREATE TABLE & CREATE INDEX statements.

    – Mr.Brownstone
    4 hours ago






  • 1





    @Mr.Brownstone added

    – Marvan Eimaz
    4 hours ago











  • Please add the output of EXPLAIN SELECT ... for your query.

    – ypercubeᵀᴹ
    14 mins ago














  • 1





    Welcome to DBA.SE! Could you post the DDL for these tables & indexes please? DDL is always better than images as it helps us recreate the issue you are having. Thanks!

    – Mr.Brownstone
    4 hours ago











  • @Mr.Brownstone What is DDL?

    – Marvan Eimaz
    4 hours ago











  • DDL stands for Data Definition Language. Essentially, the CREATE TABLE & CREATE INDEX statements.

    – Mr.Brownstone
    4 hours ago






  • 1





    @Mr.Brownstone added

    – Marvan Eimaz
    4 hours ago











  • Please add the output of EXPLAIN SELECT ... for your query.

    – ypercubeᵀᴹ
    14 mins ago








1




1





Welcome to DBA.SE! Could you post the DDL for these tables & indexes please? DDL is always better than images as it helps us recreate the issue you are having. Thanks!

– Mr.Brownstone
4 hours ago





Welcome to DBA.SE! Could you post the DDL for these tables & indexes please? DDL is always better than images as it helps us recreate the issue you are having. Thanks!

– Mr.Brownstone
4 hours ago













@Mr.Brownstone What is DDL?

– Marvan Eimaz
4 hours ago





@Mr.Brownstone What is DDL?

– Marvan Eimaz
4 hours ago













DDL stands for Data Definition Language. Essentially, the CREATE TABLE & CREATE INDEX statements.

– Mr.Brownstone
4 hours ago





DDL stands for Data Definition Language. Essentially, the CREATE TABLE & CREATE INDEX statements.

– Mr.Brownstone
4 hours ago




1




1





@Mr.Brownstone added

– Marvan Eimaz
4 hours ago





@Mr.Brownstone added

– Marvan Eimaz
4 hours ago













Please add the output of EXPLAIN SELECT ... for your query.

– ypercubeᵀᴹ
14 mins ago





Please add the output of EXPLAIN SELECT ... for your query.

– ypercubeᵀᴹ
14 mins ago










1 Answer
1






active

oldest

votes


















0














The query seems ok but you are probably missing some index. I suggest:




  • add an index on log_follow (id, other_id).

  • an index on darkhast_follower (status, id_request) might help as well but with such a small table, probably not much.

  • the datatype of the various id columns (id, other_id, id_request) are varchar(20) with charset UTF8. If you only have ASCII characters there, it would be better to use Latin charset. This will lower the column width from 60 (20x3) bytes to 20, and thus reduce the index size, both in disk and memory. If you only store integers in these columns, it would be even better to use BIGINT, reducing the size to 8 bytes.





share























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "182"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f230593%2fadvice-on-fine-tuning-query-and-index-for-performance%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The query seems ok but you are probably missing some index. I suggest:




    • add an index on log_follow (id, other_id).

    • an index on darkhast_follower (status, id_request) might help as well but with such a small table, probably not much.

    • the datatype of the various id columns (id, other_id, id_request) are varchar(20) with charset UTF8. If you only have ASCII characters there, it would be better to use Latin charset. This will lower the column width from 60 (20x3) bytes to 20, and thus reduce the index size, both in disk and memory. If you only store integers in these columns, it would be even better to use BIGINT, reducing the size to 8 bytes.





    share




























      0














      The query seems ok but you are probably missing some index. I suggest:




      • add an index on log_follow (id, other_id).

      • an index on darkhast_follower (status, id_request) might help as well but with such a small table, probably not much.

      • the datatype of the various id columns (id, other_id, id_request) are varchar(20) with charset UTF8. If you only have ASCII characters there, it would be better to use Latin charset. This will lower the column width from 60 (20x3) bytes to 20, and thus reduce the index size, both in disk and memory. If you only store integers in these columns, it would be even better to use BIGINT, reducing the size to 8 bytes.





      share


























        0












        0








        0







        The query seems ok but you are probably missing some index. I suggest:




        • add an index on log_follow (id, other_id).

        • an index on darkhast_follower (status, id_request) might help as well but with such a small table, probably not much.

        • the datatype of the various id columns (id, other_id, id_request) are varchar(20) with charset UTF8. If you only have ASCII characters there, it would be better to use Latin charset. This will lower the column width from 60 (20x3) bytes to 20, and thus reduce the index size, both in disk and memory. If you only store integers in these columns, it would be even better to use BIGINT, reducing the size to 8 bytes.





        share













        The query seems ok but you are probably missing some index. I suggest:




        • add an index on log_follow (id, other_id).

        • an index on darkhast_follower (status, id_request) might help as well but with such a small table, probably not much.

        • the datatype of the various id columns (id, other_id, id_request) are varchar(20) with charset UTF8. If you only have ASCII characters there, it would be better to use Latin charset. This will lower the column width from 60 (20x3) bytes to 20, and thus reduce the index size, both in disk and memory. If you only store integers in these columns, it would be even better to use BIGINT, reducing the size to 8 bytes.






        share











        share


        share










        answered 1 min ago









        ypercubeᵀᴹypercubeᵀᴹ

        76.9k11134214




        76.9k11134214






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Database Administrators Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f230593%2fadvice-on-fine-tuning-query-and-index-for-performance%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Szabolcs (Ungheria) Altri progetti | Menu di navigazione48°10′14.56″N 21°29′33.14″E /...

            Discografia di Klaus Schulze Indice Album in studio | Album dal vivo | Singoli | Antologie | Colonne...

            How to make inet_server_addr() return localhost in spite of ::1/128RETURN NEXT in Postgres FunctionConnect to...