I cleaned the question a little bit because it was getting very big and unreadable.

Running on my localhost.

As you can see in the image below, the query takes `755.15 ms` when selecting from the table Job that contains 15000 rows (with the where conditions returning 6650)

The table Company contains 1000 rows.
The table geo\_\_name contains 84300 rows approx and is not giving me any problem, so I believe the problem is the database structure or something.

The structure of these 2 tables is the following:

Table Job is:

```
CREATE TABLE `job` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  `company_id` int(11) NOT NULL,
  `activity_sector_id` int(11) DEFAULT NULL,
  `status` int(11) NOT NULL,
  `active` datetime NOT NULL,
  `contract_type_id` int(11) NOT NULL,
  `salary_type_id` int(11) NOT NULL,
  `workday_id` int(11) NOT NULL,
  `geoname_id` int(11) NOT NULL,
  `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `minimum_experience` int(11) DEFAULT NULL,
  `min_salary` decimal(7,2) DEFAULT NULL,
  `max_salary` decimal(7,2) DEFAULT NULL,
  `zip_code` int(11) DEFAULT NULL,
  `vacancies` int(11) DEFAULT NULL,
  `show_salary` tinyint(1) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `created_at` (`created_at`,`active`,`status`) USING BTREE,
  CONSTRAINT `FK_FBD8E0F823F5422B` FOREIGN KEY (`geoname_id`) REFERENCES `geo__name` (`id`),
  CONSTRAINT `FK_FBD8E0F8398DEFD0` FOREIGN KEY (`activity_sector_id`) REFERENCES `activity_sector` (`id`),
  CONSTRAINT `FK_FBD8E0F85248165F` FOREIGN KEY (`salary_type_id`) REFERENCES `job_salary_type` (`id`),
  CONSTRAINT `FK_FBD8E0F8979B1AD6` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`),
  CONSTRAINT `FK_FBD8E0F8AB01D695` FOREIGN KEY (`workday_id`) REFERENCES `workday` (`id`),
  CONSTRAINT `FK_FBD8E0F8CD1DF15B` FOREIGN KEY (`contract_type_id`) REFERENCES `job_contract_type` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15001 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

```

The table company is:

```
CREATE TABLE `company` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `logo` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  `website` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `user_id` int(11) NOT NULL,
  `phone` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `cifnif` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `type` int(11) NOT NULL,
  `subscription_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `UNIQ_4FBF094FA76ED395` (`user_id`),
  KEY `IDX_4FBF094F9A1887DC` (`subscription_id`),
  KEY `name` (`name`(191)),
  CONSTRAINT `FK_4FBF094F9A1887DC` FOREIGN KEY (`subscription_id`) REFERENCES `subscription` (`id`),
  CONSTRAINT `FK_4FBF094FA76ED395` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1001 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

```

The query is the following:

```
SELECT 
  j0_.id AS id_0, 
  j0_.status AS status_1, 
  j0_.title AS title_2, 
  j0_.min_salary AS min_salary_3, 
  j0_.max_salary AS max_salary_4, 
  c1_.id AS id_5, 
  c1_.name AS name_6, 
  c1_.logo AS logo_7, 
  a2_.id AS id_8, 
  a2_.name AS name_9, 
  g3_.id AS id_10, 
  g3_.name AS name_11, 
  j4_.id AS id_12, 
  j4_.name AS name_13, 
  j5_.id AS id_14, 
  j5_.name AS name_15, 
  w6_.id AS id_16, 
  w6_.name AS name_17 
FROM 
  job j0_ 
  INNER JOIN company c1_ ON j0_.company_id = c1_.id 
  INNER JOIN activity_sector a2_ ON j0_.activity_sector_id = a2_.id 
  INNER JOIN geo__name g3_ ON j0_.geoname_id = g3_.id 
  INNER JOIN job_salary_type j4_ ON j0_.salary_type_id = j4_.id 
  INNER JOIN job_contract_type j5_ ON j0_.contract_type_id = j5_.id 
  INNER JOIN workday w6_ ON j0_.workday_id = w6_.id 
WHERE 
  j0_.active >= CURRENT_TIMESTAMP 
  AND j0_.status = 1 
ORDER BY 
  j0_.created_at DESC

```

When executing the above query I have these results:

In MYSQL Workbench: `0.578 sec / 0.016 sec`
In Symfony profiler: `755.15 ms`

The question is: Is the duration of this query correct? if not, how can I improve the speed of the query? it seems too much.

[![enter image description here](https://i.stack.imgur.com/NyWlP.png)](https://i.stack.imgur.com/NyWlP.png)

The Symfony debug toolbar if it helps:

[![enter image description here](https://i.stack.imgur.com/a7JkH.png)](https://i.stack.imgur.com/a7JkH.png)

As you can see in the below image, I'm only getting the data I really need:

[![enter image description here](https://i.stack.imgur.com/aSqKJ.png)](https://i.stack.imgur.com/aSqKJ.png)

The explain query:

[![enter image description here](https://i.stack.imgur.com/LtgW9.png)](https://i.stack.imgur.com/LtgW9.png)

The timeline:

[![enter image description here](https://i.stack.imgur.com/LDpgX.png)](https://i.stack.imgur.com/LDpgX.png)