From 5f77a329fa08dd7faa03a760e351bb98c813ab7f Mon Sep 17 00:00:00 2001
From: Cristian Partica <cpartica@magento.com>
Date: Fri, 6 Jan 2017 17:56:50 -0600
Subject: [PATCH] MAGETWO-58924: SQL error wait timeout error when saving
 categories

- fix issues with code review, add phpdocs and restore BiC, rename/remove methods
---
 .../CurrentUrlRewritesRegenerator.php         | 10 +--
 .../Model/CategoryUrlRewriteGenerator.php     | 32 ++++----
 ...ategoryMap.php => DataCategoryHashMap.php} | 23 +++---
 ... => DataCategoryUrlRewriteDatabaseMap.php} | 55 ++++++-------
 ... => DataCategoryUsedInProductsHashMap.php} | 41 +++++-----
 .../Model/Map/DataMapPoolInterface.php        | 30 --------
 ...aProductMap.php => DataProductHashMap.php} | 35 ++++-----
 ...p => DataProductUrlRewriteDatabaseMap.php} | 49 ++++++------
 .../Model/Map/DatabaseMapInterface.php        | 38 +++++++++
 .../{DataMapPool.php => DatabaseMapPool.php}  | 22 ++++--
 ...aMapInterface.php => HashMapInterface.php} | 11 ++-
 .../Model/Map/HashMapPool.php                 | 77 +++++++++++++++++++
 ...UrlRewriteMap.php => UrlRewriteFinder.php} | 51 +++++++-----
 .../Product/CurrentUrlRewritesRegenerator.php | 24 +++---
 ...ategoryProcessUrlRewriteSavingObserver.php | 58 +++++++++++---
 .../CurrentUrlRewritesRegeneratorTest.php     |  2 +-
 ...apTest.php => DataCategoryHashMapTest.php} | 10 +--
 ...DataCategoryUrlRewriteDatabaseMapTest.php} | 36 ++++-----
 ...DataCategoryUsedInProductsHashMapTest.php} | 35 ++++-----
 ...MapTest.php => DataProductHashMapTest.php} | 27 ++++---
 ... DataProductUrlRewriteDatabaseMapTest.php} | 35 ++++-----
 ...ataMapPoolTest.php => HashMapPoolTest.php} | 28 +++----
 ...teMapTest.php => UrlRewriteFinderTest.php} | 48 ++++++------
 .../CurrentUrlRewritesRegeneratorTest.php     |  2 +-
 app/code/Magento/CatalogUrlRewrite/etc/di.xml |  1 -
 .../UrlRewrite/Model/UrlRewritesSet.php       |  6 +-
 .../Test/Unit/Model/UrlRewritesSetTest.php    | 14 ----
 .../Framework/DB/TemporaryTableService.php    | 29 +++----
 28 files changed, 475 insertions(+), 354 deletions(-)
 rename app/code/Magento/CatalogUrlRewrite/Model/Map/{DataCategoryMap.php => DataCategoryHashMap.php} (80%)
 rename app/code/Magento/CatalogUrlRewrite/Model/Map/{DataCategoryUrlRewriteMap.php => DataCategoryUrlRewriteDatabaseMap.php} (66%)
 rename app/code/Magento/CatalogUrlRewrite/Model/Map/{DataCategoryUsedInProductsMap.php => DataCategoryUsedInProductsHashMap.php} (66%)
 delete mode 100644 app/code/Magento/CatalogUrlRewrite/Model/Map/DataMapPoolInterface.php
 rename app/code/Magento/CatalogUrlRewrite/Model/Map/{DataProductMap.php => DataProductHashMap.php} (71%)
 rename app/code/Magento/CatalogUrlRewrite/Model/Map/{DataProductUrlRewriteMap.php => DataProductUrlRewriteDatabaseMap.php} (65%)
 create mode 100644 app/code/Magento/CatalogUrlRewrite/Model/Map/DatabaseMapInterface.php
 rename app/code/Magento/CatalogUrlRewrite/Model/Map/{DataMapPool.php => DatabaseMapPool.php} (69%)
 rename app/code/Magento/CatalogUrlRewrite/Model/Map/{DataMapInterface.php => HashMapInterface.php} (58%)
 create mode 100644 app/code/Magento/CatalogUrlRewrite/Model/Map/HashMapPool.php
 rename app/code/Magento/CatalogUrlRewrite/Model/Map/{UrlRewriteMap.php => UrlRewriteFinder.php} (64%)
 rename app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/{DataCategoryMapTest.php => DataCategoryHashMapTest.php} (93%)
 rename app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/{DataCategoryUrlRewriteMapTest.php => DataCategoryUrlRewriteDatabaseMapTest.php} (76%)
 rename app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/{DataCategoryUsedInProductsMapTest.php => DataCategoryUsedInProductsHashMapTest.php} (75%)
 rename app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/{DataProductMapTest.php => DataProductHashMapTest.php} (83%)
 rename app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/{DataProductUrlRewriteMapTest.php => DataProductUrlRewriteDatabaseMapTest.php} (73%)
 rename app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/{DataMapPoolTest.php => HashMapPoolTest.php} (63%)
 rename app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/{UrlRewriteMapTest.php => UrlRewriteFinderTest.php} (68%)

diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Category/CurrentUrlRewritesRegenerator.php b/app/code/Magento/CatalogUrlRewrite/Model/Category/CurrentUrlRewritesRegenerator.php
index b9936fa73d5..a44aee69b10 100644
--- a/app/code/Magento/CatalogUrlRewrite/Model/Category/CurrentUrlRewritesRegenerator.php
+++ b/app/code/Magento/CatalogUrlRewrite/Model/Category/CurrentUrlRewritesRegenerator.php
@@ -31,7 +31,7 @@ class CurrentUrlRewritesRegenerator
      */
     protected $urlFinder;
 
-    /** @var \Magento\CatalogUrlRewrite\Model\Map\UrlRewriteMap */
+    /** @var \Magento\CatalogUrlRewrite\Model\Map\UrlRewriteFinder */
     private $urlRewriteMap;
 
     /** @var \Magento\UrlRewrite\Model\UrlRewritesSet */
@@ -41,14 +41,14 @@ class CurrentUrlRewritesRegenerator
      * @param \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator
      * @param \Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory $urlRewriteFactory
      * @param \Magento\UrlRewrite\Model\UrlFinderInterface $urlFinder
-     * @param \Magento\CatalogUrlRewrite\Model\Map\UrlRewriteMap|null $urlRewriteMap
+     * @param \Magento\CatalogUrlRewrite\Model\Map\UrlRewriteFinder|null $urlRewriteMap
      * @param \Magento\UrlRewrite\Model\UrlRewritesSetFactory|null $urlRewritesSetFactory
      */
     public function __construct(
         \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator,
         \Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory $urlRewriteFactory,
         \Magento\UrlRewrite\Model\UrlFinderInterface $urlFinder,
-        \Magento\CatalogUrlRewrite\Model\Map\UrlRewriteMap $urlRewriteMap = null,
+        \Magento\CatalogUrlRewrite\Model\Map\UrlRewriteFinder $urlRewriteMap = null,
         \Magento\UrlRewrite\Model\UrlRewritesSetFactory $urlRewritesSetFactory = null
     ) {
         $this->categoryUrlPathGenerator = $categoryUrlPathGenerator;
@@ -56,7 +56,7 @@ class CurrentUrlRewritesRegenerator
         $this->urlRewritePrototype = $urlRewriteFactory->create();
         $this->urlFinder = $urlFinder;
         $this->urlRewriteMap = $urlRewriteMap ?: \Magento\Framework\App\ObjectManager::getInstance()
-            ->get(\Magento\CatalogUrlRewrite\Model\Map\UrlRewriteMap::class);
+            ->get(\Magento\CatalogUrlRewrite\Model\Map\UrlRewriteFinder::class);
         $urlRewritesSetFactory = $urlRewritesSetFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
             ->get(\Magento\UrlRewrite\Model\UrlRewritesSetFactory::class);
         $this->urlRewritesSetPrototype = $urlRewritesSetFactory->create();
@@ -73,7 +73,7 @@ class CurrentUrlRewritesRegenerator
     public function generate($storeId, \Magento\Catalog\Model\Category $category, $rootCategoryId = null)
     {
         $urlRewritesSet = clone $this->urlRewritesSetPrototype;
-        $currentUrlRewrites = $this->urlRewriteMap->getByIdentifiers(
+        $currentUrlRewrites = $this->urlRewriteMap->findAllByData(
             $category->getEntityId(),
             $storeId,
             CategoryUrlRewriteGenerator::ENTITY_TYPE,
diff --git a/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php b/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php
index ff3e4198332..b3b40cb2aeb 100644
--- a/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php
+++ b/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php
@@ -87,7 +87,7 @@ class CategoryUrlRewriteGenerator
         $storeId = $category->getStoreId();
         $urls = $this->isGlobalScope($storeId)
             ? $this->generateForGlobalScope($category, $overrideStoreUrls, $rootCategoryId)
-            : $this->generateForSpecificStoreView($category, $storeId, $rootCategoryId);
+            : $this->generateForSpecificStoreView($storeId, $category, $rootCategoryId);
 
         return $urls;
     }
@@ -95,12 +95,12 @@ class CategoryUrlRewriteGenerator
     /**
      * Generate list of urls for global scope
      *
-     * @param \Magento\Catalog\Model\Category $category
+     * @param \Magento\Catalog\Model\Category|null $category
      * @param bool $overrideStoreUrls
      * @param int|null $rootCategoryId
      * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
      */
-    protected function generateForGlobalScope(Category $category, $overrideStoreUrls, $rootCategoryId = null)
+    protected function generateForGlobalScope(Category $category = null, $overrideStoreUrls = false, $rootCategoryId = null)
     {
         $urlRewritesSet = clone $this->urlRewritesSetPrototype;
         $categoryId = $category->getId();
@@ -108,8 +108,8 @@ class CategoryUrlRewriteGenerator
             if (!$this->isGlobalScope($storeId)
                 && $this->isOverrideUrlsForStore($storeId, $categoryId, $overrideStoreUrls)
             ) {
-                $this->updateCategoryUrlForStore($category, $storeId);
-                $urlRewritesSet->merge($this->generateForSpecificStoreView($category, $storeId, $rootCategoryId));
+                $this->updateCategoryUrlForStore($storeId, $category);
+                $urlRewritesSet->merge($this->generateForSpecificStoreView($storeId, $category, $rootCategoryId));
             }
         }
         $result = $urlRewritesSet->getData();
@@ -122,7 +122,7 @@ class CategoryUrlRewriteGenerator
      * @param bool $overrideStoreUrls
      * @return bool
      */
-    protected function isOverrideUrlsForStore($storeId, $categoryId, $overrideStoreUrls)
+    protected function isOverrideUrlsForStore($storeId, $categoryId, $overrideStoreUrls = false)
     {
         return $overrideStoreUrls || !$this->storeViewService->doesEntityHaveOverriddenUrlKeyForStore(
             $storeId,
@@ -134,19 +134,19 @@ class CategoryUrlRewriteGenerator
     /**
      * Override url key and url path for category in specific Store
      *
-     * @param \Magento\Catalog\Model\Category $category
      * @param int $storeId
+     * @param \Magento\Catalog\Model\Category|null $category
      * @return void
      */
-    protected function updateCategoryUrlForStore(Category $category, $storeId)
+    protected function updateCategoryUrlForStore($storeId, Category $category = null)
     {
         $categoryFromRepository = $this->categoryRepository->get($category->getId(), $storeId);
-        $category->addData(
-            [
-                'url_key' => $categoryFromRepository->getUrlKey(),
-                'url_path' => $categoryFromRepository->getUrlPath()
-            ]
-        );
+            $category->addData(
+                [
+                    'url_key' => $categoryFromRepository->getUrlKey(),
+                    'url_path' => $categoryFromRepository->getUrlPath()
+                ]
+            );
     }
 
     /**
@@ -163,12 +163,12 @@ class CategoryUrlRewriteGenerator
     /**
      * Generate list of urls per store
      *
-     * @param \Magento\Catalog\Model\Category $category
      * @param string $storeId
+     * @param \Magento\Catalog\Model\Category|null $category
      * @param int|null $rootCategoryId
      * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
      */
-    protected function generateForSpecificStoreView(Category $category, $storeId, $rootCategoryId = null)
+    protected function generateForSpecificStoreView($storeId, Category $category = null, $rootCategoryId = null)
     {
         $urlRewritesSet = clone $this->urlRewritesSetPrototype;
         $urlRewritesSet->merge(
diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryMap.php b/app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryHashMap.php
similarity index 80%
rename from app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryMap.php
rename to app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryHashMap.php
index 162513f5b98..88c4ea81326 100644
--- a/app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryMap.php
+++ b/app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryHashMap.php
@@ -11,12 +11,12 @@ use Magento\Catalog\Model\CategoryRepository;
 use Magento\Catalog\Api\Data\CategoryInterface;
 
 /**
- * Map that holds data for category ids and it's subcategories ids
+ * Map that holds data for category ids and its subcategories ids
  */
-class DataCategoryMap implements DataMapInterface
+class DataCategoryHashMap implements HashMapInterface
 {
-    /** @var array */
-    private $data = [];
+    /** @var int[] */
+    private $hashMap = [];
 
     /** @var CategoryRepository */
     private $categoryRepository;
@@ -47,10 +47,10 @@ class DataCategoryMap implements DataMapInterface
      */
     public function getAllData($categoryId)
     {
-        if (empty($this->data[$categoryId])) {
-            $this->data[$categoryId] = $this->generateData($categoryId);
+        if (!isset($this->hashMap[$categoryId])) {
+            $this->hashMap[$categoryId] = $this->generateData($categoryId);
         }
-        return $this->data[$categoryId];
+        return $this->hashMap[$categoryId];
     }
 
     /**
@@ -59,7 +59,7 @@ class DataCategoryMap implements DataMapInterface
     public function getData($categoryId, $key)
     {
         $this->getAllData($categoryId);
-        return $this->data[$categoryId][$key];
+        return $this->hashMap[$categoryId][$key];
     }
 
     /**
@@ -81,7 +81,7 @@ class DataCategoryMap implements DataMapInterface
      * @param CategoryInterface $category
      * @return int[]
      */
-    private function getAllCategoryChildrenIds($category)
+    private function getAllCategoryChildrenIds(CategoryInterface $category)
     {
         $connection = $this->categoryResource->getConnection();
         $select = $connection->select()
@@ -96,9 +96,6 @@ class DataCategoryMap implements DataMapInterface
      */
     public function resetData($categoryId)
     {
-        unset($this->data[$categoryId]);
-        if (empty($this->data)) {
-            $this->data = [];
-        }
+        unset($this->hashMap[$categoryId]);
     }
 }
diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryUrlRewriteMap.php b/app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryUrlRewriteDatabaseMap.php
similarity index 66%
rename from app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryUrlRewriteMap.php
rename to app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryUrlRewriteDatabaseMap.php
index fd0bd1c9fc7..9d8894f6c5c 100644
--- a/app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryUrlRewriteMap.php
+++ b/app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryUrlRewriteDatabaseMap.php
@@ -7,19 +7,20 @@ namespace Magento\CatalogUrlRewrite\Model\Map;
 
 use Magento\Framework\App\ResourceConnection;
 use Magento\Framework\DB\TemporaryTableService;
-use \Magento\Framework\DB\Select;
+use Magento\Framework\DB\Select;
+use Magento\UrlRewrite\Model\UrlRewritesSet;
 
 /**
  * Map that holds data for category url rewrites entity
  */
-class DataCategoryUrlRewriteMap implements DataMapInterface
+class DataCategoryUrlRewriteDatabaseMap implements DatabaseMapInterface
 {
     const ENTITY_TYPE = 'category';
 
     /** @var string[] */
-    private $tableNames = [];
+    private $createdTableAdapters = [];
 
-    /** @var DataMapPoolInterface */
+    /** @var HashMapPool */
     private $dataMapPool;
 
     /** @var ResourceConnection */
@@ -30,12 +31,12 @@ class DataCategoryUrlRewriteMap implements DataMapInterface
 
     /**
      * @param ResourceConnection $connection
-     * @param DataMapPoolInterface $dataMapPool,
-     * @param TemporaryTableService $temporaryTableService,
+     * @param HashMapPool $dataMapPool,
+     * @param TemporaryTableService $temporaryTableService
      */
     public function __construct(
         ResourceConnection $connection,
-        DataMapPoolInterface $dataMapPool,
+        HashMapPool $dataMapPool,
         TemporaryTableService $temporaryTableService
     ) {
         $this->connection = $connection;
@@ -44,14 +45,16 @@ class DataCategoryUrlRewriteMap implements DataMapInterface
     }
 
     /**
-     * {@inheritdoc}
+     * Generates data from categoryId and stores it into a temporary table
+     *
+     * @param $categoryId
+     * @return void
      */
-    public function getAllData($categoryId)
+    private function generateTableAdapter($categoryId)
     {
-        if (empty($this->tableNames[$categoryId])) {
-            $this->tableNames[$categoryId] = $this->generateData($categoryId);
+        if (!isset($this->createdTableAdapters[$categoryId])) {
+            $this->createdTableAdapters[$categoryId] = $this->generateData($categoryId);
         }
-        return $this->getData($categoryId, '');
     }
 
     /**
@@ -66,7 +69,10 @@ class DataCategoryUrlRewriteMap implements DataMapInterface
         $select = $urlRewritesConnection->select()
             ->from(
                 ['e' => $this->connection->getTableName('url_rewrite')],
-                ['e.*', 'hash_key' => new \Zend_Db_Expr('CONCAT(e.store_id,\'_\', e.entity_id)')]
+                ['e.*', 'hash_key' => new \Zend_Db_Expr(
+                    "CONCAT(e.store_id,'" . UrlRewritesSet::SEPARATOR . "', e.entity_id)"
+                )
+                ]
             )
             ->where('entity_type = ?', self::ENTITY_TYPE)
             ->where(
@@ -74,9 +80,9 @@ class DataCategoryUrlRewriteMap implements DataMapInterface
                     'entity_id',
                     [
                         'in' => array_merge(
-                            $this->dataMapPool->getDataMap(DataCategoryUsedInProductsMap::class, $categoryId)
+                            $this->dataMapPool->getDataMap(DataCategoryUsedInProductsHashMap::class, $categoryId)
                                 ->getAllData($categoryId),
-                            $this->dataMapPool->getDataMap(DataCategoryMap::class, $categoryId)
+                            $this->dataMapPool->getDataMap(DataCategoryHashMap::class, $categoryId)
                                 ->getAllData($categoryId)
                         )
                     ]
@@ -97,14 +103,13 @@ class DataCategoryUrlRewriteMap implements DataMapInterface
     /**
      * {@inheritdoc}
      */
-    public function resetData($categoryId)
+    public function destroyTableAdapter($categoryId)
     {
-        $this->dataMapPool->resetDataMap(DataCategoryUsedInProductsMap::class, $categoryId);
-        $this->dataMapPool->resetDataMap(DataCategoryMap::class, $categoryId);
-        $this->temporaryTableService->dropTable($this->tableNames[$categoryId]);
-        unset($this->tableNames[$categoryId]);
-        if (empty($this->tableNames)) {
-            $this->tableNames = [];
+        $this->dataMapPool->resetMap(DataCategoryUsedInProductsHashMap::class, $categoryId);
+        $this->dataMapPool->resetMap(DataCategoryHashMap::class, $categoryId);
+        if (isset($this->createdTableAdapters[$categoryId])) {
+            $this->temporaryTableService->dropTable($this->createdTableAdapters[$categoryId]);
+            unset($this->createdTableAdapters[$categoryId]);
         }
     }
 
@@ -117,11 +122,9 @@ class DataCategoryUrlRewriteMap implements DataMapInterface
      */
     public function getData($categoryId, $key)
     {
-        if (!isset($this->tableNames[$categoryId])) {
-            $this->getAllData($categoryId);
-        }
+        $this->generateTableAdapter($categoryId);
         $urlRewritesConnection = $this->connection->getConnection();
-        $select = $urlRewritesConnection->select()->from(['e' => $this->tableNames[$categoryId]]);
+        $select = $urlRewritesConnection->select()->from(['e' => $this->createdTableAdapters[$categoryId]]);
         if (strlen($key) > 0) {
             $select->where('hash_key = ?', $key);
         }
diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryUsedInProductsMap.php b/app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryUsedInProductsHashMap.php
similarity index 66%
rename from app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryUsedInProductsMap.php
rename to app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryUsedInProductsHashMap.php
index a4d07675816..9f142ef5652 100644
--- a/app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryUsedInProductsMap.php
+++ b/app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryUsedInProductsHashMap.php
@@ -10,27 +10,27 @@ use Magento\Framework\App\ResourceConnection;
 /**
  * Map that holds data for categories used by products found in root category
  */
-class DataCategoryUsedInProductsMap implements DataMapInterface
+class DataCategoryUsedInProductsHashMap implements HashMapInterface
 {
-    /** @var array */
-    private $data = [];
+    /** @var int[] */
+    private $hashMap = [];
 
-    /** @var DataMapPoolInterface */
-    private $dataMapPool;
+    /** @var HashMapPool */
+    private $hashMapPool;
 
     /** @var ResourceConnection */
     private $connection;
 
     /**
      * @param ResourceConnection $connection
-     * @param DataMapPoolInterface $dataMapPool
+     * @param HashMapPool $hashMapPool
      */
     public function __construct(
         ResourceConnection $connection,
-        DataMapPoolInterface $dataMapPool
+        HashMapPool $hashMapPool
     ) {
         $this->connection = $connection;
-        $this->dataMapPool = $dataMapPool;
+        $this->hashMapPool = $hashMapPool;
     }
 
     /**
@@ -38,10 +38,10 @@ class DataCategoryUsedInProductsMap implements DataMapInterface
      */
     public function getAllData($categoryId)
     {
-        if (empty($this->data[$categoryId])) {
-            $this->data[$categoryId] = $this->generateData($categoryId);
+        if (!isset($this->hashMap[$categoryId])) {
+            $this->hashMap[$categoryId] = $this->generateData($categoryId);
         }
-        return $this->data[$categoryId];
+        return $this->hashMap[$categoryId];
     }
 
     /**
@@ -50,7 +50,7 @@ class DataCategoryUsedInProductsMap implements DataMapInterface
     public function getData($categoryId, $key)
     {
         $this->getAllData($categoryId);
-        return $this->data[$categoryId][$key];
+        return $this->hashMap[$categoryId][$key];
     }
 
     /**
@@ -68,8 +68,8 @@ class DataCategoryUsedInProductsMap implements DataMapInterface
                 $productsLinkConnection->prepareSqlCondition(
                     'product_id',
                     [
-                        'in' => $this->dataMapPool->getDataMap(
-                            DataProductMap::class,
+                        'in' => $this->hashMapPool->getDataMap(
+                            DataProductHashMap::class,
                             $categoryId
                         )->getAllData($categoryId)
                     ]
@@ -79,8 +79,8 @@ class DataCategoryUsedInProductsMap implements DataMapInterface
                 $productsLinkConnection->prepareSqlCondition(
                     'category_id',
                     [
-                        'nin' => $this->dataMapPool->getDataMap(
-                            DataCategoryMap::class,
+                        'nin' => $this->hashMapPool->getDataMap(
+                            DataCategoryHashMap::class,
                             $categoryId
                         )->getAllData($categoryId)
                     ]
@@ -95,11 +95,8 @@ class DataCategoryUsedInProductsMap implements DataMapInterface
      */
     public function resetData($categoryId)
     {
-        $this->dataMapPool->resetDataMap(DataProductMap::class, $categoryId);
-        $this->dataMapPool->resetDataMap(DataCategoryMap::class, $categoryId);
-        unset($this->data[$categoryId]);
-        if (empty($this->data)) {
-            $this->data = [];
-        }
+        $this->hashMapPool->resetMap(DataProductHashMap::class, $categoryId);
+        $this->hashMapPool->resetMap(DataCategoryHashMap::class, $categoryId);
+        unset($this->hashMap[$categoryId]);
     }
 }
diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Map/DataMapPoolInterface.php b/app/code/Magento/CatalogUrlRewrite/Model/Map/DataMapPoolInterface.php
deleted file mode 100644
index b3a30303a90..00000000000
--- a/app/code/Magento/CatalogUrlRewrite/Model/Map/DataMapPoolInterface.php
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-/**
- * Copyright © 2017 Magento. All rights reserved.
- * See COPYING.txt for license details.
- */
-namespace Magento\CatalogUrlRewrite\Model\Map;
-
-/**
- * Interface for data map pool
- */
-interface DataMapPoolInterface
-{
-    /**
-     * Gets a map by instance and category Id
-     *
-     * @param string $instanceName
-     * @param int $categoryId
-     * @return DataMapInterface
-     */
-    public function getDataMap($instanceName, $categoryId);
-
-    /**
-     * Resets a map by instance and category Id
-     *
-     * @param string $instanceName
-     * @param int $categoryId
-     * @return void
-     */
-    public function resetDataMap($instanceName, $categoryId);
-}
diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Map/DataProductMap.php b/app/code/Magento/CatalogUrlRewrite/Model/Map/DataProductHashMap.php
similarity index 71%
rename from app/code/Magento/CatalogUrlRewrite/Model/Map/DataProductMap.php
rename to app/code/Magento/CatalogUrlRewrite/Model/Map/DataProductHashMap.php
index 436790e41c2..44aaca3b466 100644
--- a/app/code/Magento/CatalogUrlRewrite/Model/Map/DataProductMap.php
+++ b/app/code/Magento/CatalogUrlRewrite/Model/Map/DataProductHashMap.php
@@ -11,32 +11,32 @@ use Magento\Framework\App\ResourceConnection;
 /**
  * Map that holds data for products ids from a category and subcategories
  */
-class DataProductMap implements DataMapInterface
+class DataProductHashMap implements HashMapInterface
 {
-    /** @var array */
-    private $data = [];
+    /** @var int[] */
+    private $hashMap = [];
 
     /** @var CollectionFactory */
     private $collectionFactory;
 
-    /** @var DataMapPoolInterface */
-    private $dataMapPool;
+    /** @var HashMapPool */
+    private $hashMapPool;
 
     /** @var ResourceConnection */
     private $connection;
 
     /**
      * @param CollectionFactory $collectionFactory
-     * @param DataMapPoolInterface $dataMapPool
+     * @param HashMapPool $hashMapPool
      * @param ResourceConnection $connection
      */
     public function __construct(
         CollectionFactory $collectionFactory,
-        DataMapPoolInterface $dataMapPool,
+        HashMapPool $hashMapPool,
         ResourceConnection $connection
     ) {
         $this->collectionFactory = $collectionFactory;
-        $this->dataMapPool = $dataMapPool;
+        $this->hashMapPool = $hashMapPool;
         $this->connection = $connection;
     }
 
@@ -45,10 +45,10 @@ class DataProductMap implements DataMapInterface
      */
     public function getAllData($categoryId)
     {
-        if (empty($this->data[$categoryId])) {
-            $this->data[$categoryId] = $this->generateData($categoryId);
+        if (!isset($this->hashMap[$categoryId])) {
+            $this->hashMap[$categoryId] = $this->generateData($categoryId);
         }
-        return $this->data[$categoryId];
+        return $this->hashMap[$categoryId];
     }
 
     /**
@@ -57,7 +57,7 @@ class DataProductMap implements DataMapInterface
     public function getData($categoryId, $key)
     {
         $this->getAllData($categoryId);
-        return $this->data[$categoryId][$key];
+        return $this->hashMap[$categoryId][$key];
     }
 
     /**
@@ -79,8 +79,8 @@ class DataProductMap implements DataMapInterface
                 $productsCollection->getConnection()->prepareSqlCondition(
                     'cp.category_id',
                     [
-                        'in' => $this->dataMapPool->getDataMap(
-                            DataCategoryMap::class,
+                        'in' => $this->hashMapPool->getDataMap(
+                            DataCategoryHashMap::class,
                             $categoryId
                         )->getAllData($categoryId)
                     ]
@@ -95,10 +95,7 @@ class DataProductMap implements DataMapInterface
      */
     public function resetData($categoryId)
     {
-        $this->dataMapPool->resetDataMap(DataCategoryMap::class, $categoryId);
-        unset($this->data[$categoryId]);
-        if (empty($this->data)) {
-            $this->data = [];
-        }
+        $this->hashMapPool->resetMap(DataCategoryHashMap::class, $categoryId);
+        unset($this->hashMap[$categoryId]);
     }
 }
diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Map/DataProductUrlRewriteMap.php b/app/code/Magento/CatalogUrlRewrite/Model/Map/DataProductUrlRewriteDatabaseMap.php
similarity index 65%
rename from app/code/Magento/CatalogUrlRewrite/Model/Map/DataProductUrlRewriteMap.php
rename to app/code/Magento/CatalogUrlRewrite/Model/Map/DataProductUrlRewriteDatabaseMap.php
index 31f172584e3..609841a2a87 100644
--- a/app/code/Magento/CatalogUrlRewrite/Model/Map/DataProductUrlRewriteMap.php
+++ b/app/code/Magento/CatalogUrlRewrite/Model/Map/DataProductUrlRewriteDatabaseMap.php
@@ -7,20 +7,21 @@ namespace Magento\CatalogUrlRewrite\Model\Map;
 
 use Magento\Framework\App\ResourceConnection;
 use Magento\Framework\DB\TemporaryTableService;
-use \Magento\Framework\DB\Select;
+use Magento\Framework\DB\Select;
+use Magento\UrlRewrite\Model\UrlRewritesSet;
 
 /**
  * Map that holds data for category url rewrites entity
  * @SuppressWarnings(PHPCPD)
  */
-class DataProductUrlRewriteMap implements DataMapInterface
+class DataProductUrlRewriteDatabaseMap implements DatabaseMapInterface
 {
     const ENTITY_TYPE = 'product';
 
     /** @var string[] */
-    private $tableNames = [];
+    private $createdTableAdapters = [];
 
-    /** @var DataMapPoolInterface */
+    /** @var HashMapPool */
     private $dataMapPool;
 
     /** @var ResourceConnection */
@@ -31,12 +32,12 @@ class DataProductUrlRewriteMap implements DataMapInterface
 
     /**
      * @param ResourceConnection $connection
-     * @param DataMapPoolInterface $dataMapPool,
-     * @param TemporaryTableService $temporaryTableService,
+     * @param HashMapPool $dataMapPool,
+     * @param TemporaryTableService $temporaryTableService
      */
     public function __construct(
         ResourceConnection $connection,
-        DataMapPoolInterface $dataMapPool,
+        HashMapPool $dataMapPool,
         TemporaryTableService $temporaryTableService
     ) {
         $this->connection = $connection;
@@ -45,14 +46,16 @@ class DataProductUrlRewriteMap implements DataMapInterface
     }
 
     /**
-     * {@inheritdoc}
+     * Generates data from categoryId and stores it into a temporary table
+     *
+     * @param $categoryId
+     * @return void
      */
-    public function getAllData($categoryId)
+    private function generateTableAdapter($categoryId)
     {
-        if (empty($this->tableNames[$categoryId])) {
-            $this->tableNames[$categoryId] = $this->generateData($categoryId);
+        if (!isset($this->createdTableAdapters[$categoryId])) {
+            $this->createdTableAdapters[$categoryId] = $this->generateData($categoryId);
         }
-        return $this->tableNames[$categoryId];
     }
 
     /**
@@ -60,10 +63,10 @@ class DataProductUrlRewriteMap implements DataMapInterface
      */
     public function getData($categoryId, $key)
     {
-        $this->getAllData($categoryId);
+        $this->generateTableAdapter($categoryId);
         $urlRewritesConnection = $this->connection->getConnection();
         $select = $urlRewritesConnection->select()
-            ->from(['e' => $this->tableNames[$categoryId]])
+            ->from(['e' => $this->createdTableAdapters[$categoryId]])
             ->where('hash_key = ?', $key);
         return $urlRewritesConnection->fetchAll($select);
     }
@@ -80,14 +83,17 @@ class DataProductUrlRewriteMap implements DataMapInterface
         $select = $urlRewritesConnection->select()
             ->from(
                 ['e' => $this->connection->getTableName('url_rewrite')],
-                ['e.*', 'hash_key' => new \Zend_Db_Expr('CONCAT(e.store_id,\'_\', e.entity_id)')]
+                ['e.*', 'hash_key' => new \Zend_Db_Expr(
+                    "CONCAT(e.store_id,'" . UrlRewritesSet::SEPARATOR . "', e.entity_id)"
+                )
+                ]
             )
             ->where('entity_type = ?', self::ENTITY_TYPE)
             ->where(
                 $urlRewritesConnection->prepareSqlCondition(
                     'entity_id',
                     [
-                        'in' => $this->dataMapPool->getDataMap(DataProductMap::class, $categoryId)
+                        'in' => $this->dataMapPool->getDataMap(DataProductHashMap::class, $categoryId)
                             ->getAllData($categoryId)
                     ]
                 )
@@ -107,13 +113,12 @@ class DataProductUrlRewriteMap implements DataMapInterface
     /**
      * {@inheritdoc}
      */
-    public function resetData($categoryId)
+    public function destroyTableAdapter($categoryId)
     {
-        $this->dataMapPool->resetDataMap(DataProductMap::class, $categoryId);
-        $this->temporaryTableService->dropTable($this->tableNames[$categoryId]);
-        unset($this->tableNames[$categoryId]);
-        if (empty($this->tableNames)) {
-            $this->tableNames = [];
+        $this->dataMapPool->resetMap(DataProductHashMap::class, $categoryId);
+        if (isset($this->createdTableAdapters[$categoryId])) {
+            $this->temporaryTableService->dropTable($this->createdTableAdapters[$categoryId]);
+            unset($this->createdTableAdapters[$categoryId]);
         }
     }
 }
diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Map/DatabaseMapInterface.php b/app/code/Magento/CatalogUrlRewrite/Model/Map/DatabaseMapInterface.php
new file mode 100644
index 00000000000..6090baf3d90
--- /dev/null
+++ b/app/code/Magento/CatalogUrlRewrite/Model/Map/DatabaseMapInterface.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Copyright © 2017 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\CatalogUrlRewrite\Model\Map;
+
+use \Magento\Framework\DB\Select;
+
+/**
+ * Interface for a mysql data type of a map
+ * Is used to get data by a unique key from a temporary table in mysql to prevent memory usage
+ * It internally holds the knowledge the creation of the actual data and it initializes itself when we call getData
+ * We should always call destroyTableAdapter when we don't need anymore the temporary tables
+ */
+interface DatabaseMapInterface
+{
+    /**
+     * Gets data by key from a map identified by a category Id
+     * The key is a unique identifier that matches the values of the index used to build the temporary table
+     *
+     * Example "1_2" where ids would correspond to store_id entity_id
+     *
+     * @param int $categoryId
+     * @param string $key
+     * @return array
+     */
+    public function getData($categoryId, $key);
+
+    /**
+     * Destroys data in the temporary table by categoryId
+     * It also destroys the data in other maps that are dependencies used to construct the data
+     *
+     * @param int $categoryId
+     * @return void
+     */
+    public function destroyTableAdapter($categoryId);
+}
diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Map/DataMapPool.php b/app/code/Magento/CatalogUrlRewrite/Model/Map/DatabaseMapPool.php
similarity index 69%
rename from app/code/Magento/CatalogUrlRewrite/Model/Map/DataMapPool.php
rename to app/code/Magento/CatalogUrlRewrite/Model/Map/DatabaseMapPool.php
index d6238c41302..942f92c234c 100644
--- a/app/code/Magento/CatalogUrlRewrite/Model/Map/DataMapPool.php
+++ b/app/code/Magento/CatalogUrlRewrite/Model/Map/DatabaseMapPool.php
@@ -8,12 +8,12 @@ namespace Magento\CatalogUrlRewrite\Model\Map;
 use Magento\Framework\ObjectManagerInterface;
 
 /**
- * Pool for all data maps
+ * Pool for database maps
  */
-class DataMapPool implements DataMapPoolInterface
+class DatabaseMapPool
 {
     /**
-     * @var DataMapInterface[]
+     * @var DatabaseMapInterface[]
      */
     private $dataArray = [];
 
@@ -34,7 +34,11 @@ class DataMapPool implements DataMapPoolInterface
     }
 
     /**
-     * {@inheritdoc}
+     * Gets a map by instance and category Id
+     *
+     * @param string $instanceName
+     * @param int $categoryId
+     * @return DatabaseMapInterface
      */
     public function getDataMap($instanceName, $categoryId)
     {
@@ -51,13 +55,17 @@ class DataMapPool implements DataMapPoolInterface
     }
 
     /**
-     * {@inheritdoc}
+     * Resets a database map by instance and category Id
+     *
+     * @param string $instanceName
+     * @param int $categoryId
+     * @return void
      */
-    public function resetDataMap($instanceName, $categoryId)
+    public function resetMap($instanceName, $categoryId)
     {
         $key = $instanceName . '-' . $categoryId;
         if (isset($this->dataArray[$key])) {
-            $this->dataArray[$key]->resetData($categoryId);
+            $this->dataArray[$key]->destroyTableAdapter($categoryId);
             unset($this->dataArray[$key]);
         }
     }
diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Map/DataMapInterface.php b/app/code/Magento/CatalogUrlRewrite/Model/Map/HashMapInterface.php
similarity index 58%
rename from app/code/Magento/CatalogUrlRewrite/Model/Map/DataMapInterface.php
rename to app/code/Magento/CatalogUrlRewrite/Model/Map/HashMapInterface.php
index 97d4d3ab646..ec23104f5d8 100644
--- a/app/code/Magento/CatalogUrlRewrite/Model/Map/DataMapInterface.php
+++ b/app/code/Magento/CatalogUrlRewrite/Model/Map/HashMapInterface.php
@@ -8,9 +8,14 @@ namespace Magento\CatalogUrlRewrite\Model\Map;
 use \Magento\Framework\DB\Select;
 
 /**
- * Interface for a data map
+ * Interface for a hash data map
+ * It is used for classes tht would build hash maps and store them into memory
+ * The initialization is done transparently whenever getAllData or getData is called
+ * The map, upon initialization, might have a dependency on some other DataMapInterfaces
+ * The map has to free memory after we're done using it
+ * We need to destroy those maps too when calling resetData
  */
-interface DataMapInterface
+interface HashMapInterface
 {
     /**
      * Gets all data from a map identified by a category Id
@@ -30,7 +35,7 @@ interface DataMapInterface
     public function getData($categoryId, $key);
 
     /**
-     * Resets current map and it's dependencies
+     * Resets current map by freeing memory and also to its dependencies
      *
      * @param int $categoryId
      * @return void
diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Map/HashMapPool.php b/app/code/Magento/CatalogUrlRewrite/Model/Map/HashMapPool.php
new file mode 100644
index 00000000000..7c424cd7738
--- /dev/null
+++ b/app/code/Magento/CatalogUrlRewrite/Model/Map/HashMapPool.php
@@ -0,0 +1,77 @@
+<?php
+/**
+ * Copyright © 2017 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\CatalogUrlRewrite\Model\Map;
+
+use Magento\Framework\ObjectManagerInterface;
+
+/**
+ * Pool for hash maps
+ */
+class HashMapPool
+{
+    /**
+     * @var HashMapInterface[]
+     */
+    private $dataArray = [];
+
+    /**
+     * @var ObjectManagerInterface
+     */
+    private $objectManager;
+
+    /**
+     * Constructor
+     *
+     * @param ObjectManagerInterface $objectManager
+     */
+    public function __construct(
+        ObjectManagerInterface $objectManager
+    ) {
+        $this->objectManager = $objectManager;
+    }
+
+    /**
+     * Gets a map by instance and category Id
+     *
+     * @param string $instanceName
+     * @param int $categoryId
+     * @return HashMapInterface
+     * @throws \Exception
+     */
+    public function getDataMap($instanceName, $categoryId)
+    {
+        $key = $instanceName . '-' . $categoryId;
+        $reflectionClass = new \ReflectionClass($instanceName);
+        if (!$reflectionClass->implementsInterface(HashMapInterface::class)) {
+           throw new \Exception($instanceName . ' does not implement interface ' . HashMapInterface::class);
+        }
+        if (!isset($this->dataArray[$key])) {
+            $this->dataArray[$key] = $this->objectManager->create(
+                $instanceName,
+                [
+                    'category' => $categoryId
+                ]
+            );
+        }
+        return $this->dataArray[$key];
+    }
+
+    /**
+     * Resets data in a hash map by instance name and category Id
+     *
+     * @param string $instanceName
+     * @param int $categoryId
+     * @return void
+     */
+    public function resetMap($instanceName, $categoryId)
+    {
+        $key = $instanceName . '-' . $categoryId;
+        if (isset($this->dataArray[$key])) {
+            $this->dataArray[$key]->resetData($categoryId);
+            unset($this->dataArray[$key]);
+        }
+    }
+}
diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Map/UrlRewriteMap.php b/app/code/Magento/CatalogUrlRewrite/Model/Map/UrlRewriteFinder.php
similarity index 64%
rename from app/code/Magento/CatalogUrlRewrite/Model/Map/UrlRewriteMap.php
rename to app/code/Magento/CatalogUrlRewrite/Model/Map/UrlRewriteFinder.php
index 70bb44c75b8..52bf538aa34 100644
--- a/app/code/Magento/CatalogUrlRewrite/Model/Map/UrlRewriteMap.php
+++ b/app/code/Magento/CatalogUrlRewrite/Model/Map/UrlRewriteFinder.php
@@ -11,15 +11,16 @@ use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
 use Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory;
 
 /**
- * Allows query to DataCategoryUrlRewriteMap and DataProductUrlRewriteMap class or UrlFinderInterface by identifiers
+ * Allows query to Category and Product UrlRewrite Database Map or UrlFinderInterface by identifiers
+ *
  */
-class UrlRewriteMap
+class UrlRewriteFinder
 {
     const ENTITY_TYPE_CATEGORY = 'category';
     const ENTITY_TYPE_PRODUCT = 'product';
 
-    /** @var DataMapPoolInterface */
-    private $dataMapPool;
+    /** @var DatabaseMapPool */
+    private $databaseMapPool;
 
     /** @var UrlFinderInterface */
     private $urlFinder;
@@ -27,18 +28,27 @@ class UrlRewriteMap
     /** @var UrlRewrite */
     private $urlRewritePrototype;
 
+    /** @var array */
+    private $urlRewriteClassNames;
+
     /**
-     * @param DataMapPoolInterface $dataMapPool
+     * @param DatabaseMapPool $databaseMapPool
      * @param UrlFinderInterface $urlFinder
      * @param UrlRewriteFactory $urlRewriteFactory
+     * @param string[] $urlRewriteClassNames
      */
     public function __construct(
-        DataMapPoolInterface $dataMapPool,
+        DatabaseMapPool $databaseMapPool,
         UrlFinderInterface $urlFinder,
-        UrlRewriteFactory $urlRewriteFactory
+        UrlRewriteFactory $urlRewriteFactory,
+        array $urlRewriteClassNames = [
+            self::ENTITY_TYPE_PRODUCT => DataProductUrlRewriteDatabaseMap::class,
+            self::ENTITY_TYPE_CATEGORY => DataCategoryUrlRewriteDatabaseMap::class
+        ]
     ) {
-        $this->dataMapPool = $dataMapPool;
+        $this->databaseMapPool = $databaseMapPool;
         $this->urlFinder = $urlFinder;
+        $this->urlRewriteClassNames = $urlRewriteClassNames;
         $this->urlRewritePrototype = $urlRewriteFactory->create();
     }
 
@@ -51,16 +61,15 @@ class UrlRewriteMap
      * @param int|null $rootCategoryId
      * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
      */
-    public function getByIdentifiers($entityId, $storeId, $entityType, $rootCategoryId = null)
+    public function findAllByData($entityId, $storeId, $entityType, $rootCategoryId = null)
     {
-        if ($rootCategoryId && is_numeric($entityId) && is_numeric($storeId) && is_string($entityType)) {
-            $map = null;
-            if ($entityType === self::ENTITY_TYPE_PRODUCT) {
-                $map = $this->dataMapPool->getDataMap(DataProductUrlRewriteMap::class, $rootCategoryId);
-            } elseif ($entityType === self::ENTITY_TYPE_CATEGORY) {
-                $map = $this->dataMapPool->getDataMap(DataCategoryUrlRewriteMap::class, $rootCategoryId);
-            }
-
+        if ($rootCategoryId
+            && is_numeric($entityId)
+            && is_numeric($storeId)
+            && is_string($entityType)
+            && isset($this->urlRewriteClassNames[$entityType])
+        ) {
+            $map = $this->databaseMapPool->getDataMap($this->urlRewriteClassNames[$entityType], $rootCategoryId);
             if ($map) {
                 $key = $storeId . '_' . $entityId;
                 return $this->arrayToUrlRewriteObject($map->getData($rootCategoryId, $key));
@@ -77,12 +86,12 @@ class UrlRewriteMap
     }
 
     /**
-     * Transform array values to url rewrite object values
+     * Transfer array values to url rewrite object values
      *
      * @param array $data
      * @return UrlRewrite[]
      */
-    private function arrayToUrlRewriteObject($data)
+    private function arrayToUrlRewriteObject(array $data)
     {
         foreach ($data as $key => $array) {
             $data[$key] = $this->createUrlRewrite($array);
@@ -91,12 +100,12 @@ class UrlRewriteMap
     }
 
     /**
-     * Clone url rewrite object
+     * Creates url rewrite object and sets $data to its properties by key->value
      *
      * @param array $data
      * @return UrlRewrite
      */
-    private function createUrlRewrite($data)
+    private function createUrlRewrite(array $data)
     {
         $dataObject = clone $this->urlRewritePrototype;
         $dataObject->setUrlRewriteId($data['url_rewrite_id']);
diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Product/CurrentUrlRewritesRegenerator.php b/app/code/Magento/CatalogUrlRewrite/Model/Product/CurrentUrlRewritesRegenerator.php
index ddb91986f24..9f49646e4e4 100644
--- a/app/code/Magento/CatalogUrlRewrite/Model/Product/CurrentUrlRewritesRegenerator.php
+++ b/app/code/Magento/CatalogUrlRewrite/Model/Product/CurrentUrlRewritesRegenerator.php
@@ -14,7 +14,7 @@ use Magento\UrlRewrite\Model\UrlFinderInterface;
 use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
 use Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator;
 use Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory;
-use Magento\CatalogUrlRewrite\Model\Map\UrlRewriteMap;
+use Magento\CatalogUrlRewrite\Model\Map\UrlRewriteFinder;
 use Magento\Framework\App\ObjectManager;
 use Magento\UrlRewrite\Model\UrlRewritesSetFactory;
 
@@ -50,7 +50,7 @@ class CurrentUrlRewritesRegenerator
     /** @var UrlRewrite */
     private $urlRewritePrototype;
 
-    /** @var UrlRewriteMap */
+    /** @var UrlRewriteFinder */
     private $urlRewriteMap;
 
     /** @var \Magento\UrlRewrite\Model\UrlRewritesSet */
@@ -60,21 +60,21 @@ class CurrentUrlRewritesRegenerator
      * @param UrlFinderInterface $urlFinder
      * @param ProductUrlPathGenerator $productUrlPathGenerator
      * @param UrlRewriteFactory $urlRewriteFactory
-     * @param UrlRewriteMap|null $urlRewriteMap
+     * @param UrlRewriteFinder|null $urlRewriteMap
      * @param \Magento\UrlRewrite\Model\UrlRewritesSetFactory|null $urlRewritesSetFactory
      */
     public function __construct(
         UrlFinderInterface $urlFinder,
         ProductUrlPathGenerator $productUrlPathGenerator,
         UrlRewriteFactory $urlRewriteFactory,
-        UrlRewriteMap $urlRewriteMap = null,
+        UrlRewriteFinder $urlRewriteMap = null,
         UrlRewritesSetFactory $urlRewritesSetFactory = null
     ) {
         $this->urlFinder = $urlFinder;
         $this->productUrlPathGenerator = $productUrlPathGenerator;
         $this->urlRewriteFactory = $urlRewriteFactory;
         $this->urlRewritePrototype = $urlRewriteFactory->create();
-        $this->urlRewriteMap = $urlRewriteMap ?: ObjectManager::getInstance()->get(UrlRewriteMap::class);
+        $this->urlRewriteMap = $urlRewriteMap ?: ObjectManager::getInstance()->get(UrlRewriteFinder::class);
         $urlRewritesSetFactory = $urlRewritesSetFactory ?: ObjectManager::getInstance()
             ->get(UrlRewritesSetFactory::class);
         $this->urlRewritesSetPrototype = $urlRewritesSetFactory->create();
@@ -92,7 +92,7 @@ class CurrentUrlRewritesRegenerator
     public function generate($storeId, Product $product, ObjectRegistry $productCategories, $rootCategoryId = null)
     {
         $urlRewritesSet = clone $this->urlRewritesSetPrototype;
-        $currentUrlRewrites = $this->urlRewriteMap->getByIdentifiers(
+        $currentUrlRewrites = $this->urlRewriteMap->findAllByData(
             $product->getEntityId(),
             $storeId,
             ProductUrlRewriteGenerator::ENTITY_TYPE,
@@ -118,10 +118,10 @@ class CurrentUrlRewritesRegenerator
      * @param UrlRewrite $url
      * @param int $storeId
      * @param Category|null $category
-     * @param Product $product
+     * @param Product|null $product
      * @return UrlRewrite[]
      */
-    protected function generateForAutogenerated(UrlRewrite $url, $storeId, $category, Product $product)
+    protected function generateForAutogenerated($url, $storeId, $category, $product = null)
     {
         if ($product->getData('save_rewrites_history')) {
             $targetPath = $this->productUrlPathGenerator->getUrlPathWithSuffix($product, $storeId, $category);
@@ -146,10 +146,10 @@ class CurrentUrlRewritesRegenerator
      * @param UrlRewrite $url
      * @param int $storeId
      * @param Category|null $category
-     * @param Product $product
+     * @param Product|null $product
      * @return UrlRewrite[]
      */
-    protected function generateForCustom(UrlRewrite $url, $storeId, $category, Product $product)
+    protected function generateForCustom($url, $storeId, $category, $product = null)
     {
         $targetPath = $url->getRedirectType()
             ? $this->productUrlPathGenerator->getUrlPathWithSuffix($product, $storeId, $category)
@@ -172,10 +172,10 @@ class CurrentUrlRewritesRegenerator
 
     /**
      * @param UrlRewrite $url
-     * @param ObjectRegistry $productCategories
+     * @param ObjectRegistry|null $productCategories
      * @return Category|null|bool
      */
-    protected function retrieveCategoryFromMetadata(UrlRewrite $url, ObjectRegistry $productCategories)
+    protected function retrieveCategoryFromMetadata($url, ObjectRegistry $productCategories = null)
     {
         $metadata = $url->getMetadata();
         if (isset($metadata['category_id'])) {
diff --git a/app/code/Magento/CatalogUrlRewrite/Observer/CategoryProcessUrlRewriteSavingObserver.php b/app/code/Magento/CatalogUrlRewrite/Observer/CategoryProcessUrlRewriteSavingObserver.php
index 2820f909944..71a68ef340a 100644
--- a/app/code/Magento/CatalogUrlRewrite/Observer/CategoryProcessUrlRewriteSavingObserver.php
+++ b/app/code/Magento/CatalogUrlRewrite/Observer/CategoryProcessUrlRewriteSavingObserver.php
@@ -9,9 +9,9 @@ use Magento\Catalog\Model\Category;
 use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
 use Magento\CatalogUrlRewrite\Model\UrlRewriteBunchReplacer;
 use Magento\Framework\Event\ObserverInterface;
-use Magento\CatalogUrlRewrite\Model\Map\DataMapPoolInterface;
-use Magento\CatalogUrlRewrite\Model\Map\DataProductUrlRewriteMap;
-use Magento\CatalogUrlRewrite\Model\Map\DataCategoryUrlRewriteMap;
+use Magento\CatalogUrlRewrite\Model\Map\DatabaseMapPool;
+use Magento\CatalogUrlRewrite\Model\Map\DataCategoryUrlRewriteDatabaseMap;
+use Magento\CatalogUrlRewrite\Model\Map\DataProductUrlRewriteDatabaseMap;
 
 class CategoryProcessUrlRewriteSavingObserver implements ObserverInterface
 {
@@ -24,25 +24,34 @@ class CategoryProcessUrlRewriteSavingObserver implements ObserverInterface
     /** @var UrlRewriteHandler */
     private $urlRewriteHandler;
 
-    /** @var DataMapPoolInterface */
-    private $dataMapPoolInterface;
+    /** @var DatabaseMapPool */
+    private $databaseMapPool;
+
+    /** @var string[] */
+    private $dataUrlRewriteClassNames;
 
     /**
      * @param CategoryUrlRewriteGenerator $categoryUrlRewriteGenerator
      * @param UrlRewriteHandler $urlRewriteHandler
      * @param UrlRewriteBunchReplacer $urlRewriteBunchReplacer
-     * @param DataMapPoolInterface $dataMapPoolInterface
+     * @param DatabaseMapPool $databaseMapPool
+     * @param string[] $dataUrlRewriteClassNames
      */
     public function __construct(
         CategoryUrlRewriteGenerator $categoryUrlRewriteGenerator,
         UrlRewriteHandler $urlRewriteHandler,
         UrlRewriteBunchReplacer $urlRewriteBunchReplacer,
-        DataMapPoolInterface $dataMapPoolInterface
+        DatabaseMapPool $databaseMapPool,
+        array $dataUrlRewriteClassNames = [
+            DataCategoryUrlRewriteDatabaseMap::class,
+            DataProductUrlRewriteDatabaseMap::class
+        ]
     ) {
         $this->categoryUrlRewriteGenerator = $categoryUrlRewriteGenerator;
         $this->urlRewriteHandler = $urlRewriteHandler;
         $this->urlRewriteBunchReplacer = $urlRewriteBunchReplacer;
-        $this->dataMapPoolInterface = $dataMapPoolInterface;
+        $this->databaseMapPool = $databaseMapPool;
+        $this->dataUrlRewriteClassNames = $dataUrlRewriteClassNames;
     }
 
     /**
@@ -62,14 +71,43 @@ class CategoryProcessUrlRewriteSavingObserver implements ObserverInterface
             || $category->dataHasChangedFor('is_anchor')
             || $category->getIsChangedProductList()
         ) {
+            $this->initializeUrlRewritesDataMaps($category);
+
             $categoryUrlRewriteResult = $this->categoryUrlRewriteGenerator->generate($category);
             $this->urlRewriteBunchReplacer->doBunchReplace($categoryUrlRewriteResult);
 
             $productUrlRewriteResult = $this->urlRewriteHandler->generateProductUrlRewrites($category);
             $this->urlRewriteBunchReplacer->doBunchReplace($productUrlRewriteResult);
 
-            $this->dataMapPoolInterface->resetDataMap(DataCategoryUrlRewriteMap::class, $category->getEntityId());
-            $this->dataMapPoolInterface->resetDataMap(DataProductUrlRewriteMap::class, $category->getEntityId());
+            $this->resetUrlRewritesDataMaps($category);
+        }
+    }
+
+    /**
+     * Initializes data maps to be further used
+     *
+     * @param Category $category
+     * @return void
+     */
+    private function initializeUrlRewritesDataMaps($category)
+    {
+        foreach ($this->dataUrlRewriteClassNames as $className) {
+            $this->databaseMapPool->getDataMap($className, $category->getEntityId());
+        }
+
+    }
+
+    /**
+     * Resets used data maps to free up memory and temporary tables
+     *
+     * @param Category $category
+     * @return void
+     */
+    private function resetUrlRewritesDataMaps($category)
+    {
+        foreach ($this->dataUrlRewriteClassNames as $className) {
+            $this->databaseMapPool->resetMap($className, $category->getEntityId());
         }
+
     }
 }
diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Category/CurrentUrlRewritesRegeneratorTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Category/CurrentUrlRewritesRegeneratorTest.php
index cae82e325cc..b70c3d33a15 100644
--- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Category/CurrentUrlRewritesRegeneratorTest.php
+++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Category/CurrentUrlRewritesRegeneratorTest.php
@@ -46,7 +46,7 @@ class CurrentUrlRewritesRegeneratorTest extends \PHPUnit_Framework_TestCase
         $this->categoryUrlPathGenerator = $this->getMockBuilder(
             \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator::class
         )->disableOriginalConstructor()->getMock();
-        $this->urlRewriteMap = $this->getMockBuilder(\Magento\CatalogUrlRewrite\Model\Map\UrlRewriteMap::class)
+        $this->urlRewriteMap = $this->getMockBuilder(\Magento\CatalogUrlRewrite\Model\Map\UrlRewriteFinder::class)
             ->disableOriginalConstructor()->getMock();
         $this->urlRewriteFactory->expects($this->once())->method('create')
             ->willReturn($this->urlRewrite);
diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryMapTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryHashMapTest.php
similarity index 93%
rename from app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryMapTest.php
rename to app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryHashMapTest.php
index c0d3d1a0d75..bdca177eee3 100644
--- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryMapTest.php
+++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryHashMapTest.php
@@ -10,14 +10,14 @@ use Magento\Catalog\Model\ResourceModel\Category as CategoryResource;
 use Magento\Framework\DB\Select;
 use Magento\Catalog\Model\CategoryRepository;
 use Magento\Catalog\Api\Data\CategoryInterface;
-use Magento\CatalogUrlRewrite\Model\Map\DataCategoryMap;
+use Magento\CatalogUrlRewrite\Model\Map\DataCategoryHashMap;
 use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
 use Magento\Framework\DB\Adapter\AdapterInterface;
 
 /**
- * Class DataCategoryMapTest
+ * Class DataCategoryHashMapTest
  */
-class DataCategoryMapTest extends \PHPUnit_Framework_TestCase
+class DataCategoryHashMapTest extends \PHPUnit_Framework_TestCase
 {
     /** @var CategoryRepository|\PHPUnit_Framework_MockObject_MockObject */
     private $categoryRepository;
@@ -28,7 +28,7 @@ class DataCategoryMapTest extends \PHPUnit_Framework_TestCase
     /** @var CategoryResource|\PHPUnit_Framework_MockObject_MockObject */
     private $categoryResource;
 
-    /** @var DataCategoryMap|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var DataCategoryHashMap|\PHPUnit_Framework_MockObject_MockObject */
     private $model;
 
     protected function setUp()
@@ -44,7 +44,7 @@ class DataCategoryMapTest extends \PHPUnit_Framework_TestCase
         );
 
         $this->model = (new ObjectManager($this))->getObject(
-            DataCategoryMap::class,
+            DataCategoryHashMap::class,
             [
                 'categoryRepository' => $this->categoryRepository,
                 'collection' => $this->collection,
diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryUrlRewriteMapTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryUrlRewriteDatabaseMapTest.php
similarity index 76%
rename from app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryUrlRewriteMapTest.php
rename to app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryUrlRewriteDatabaseMapTest.php
index 7018323e007..396e00310fe 100644
--- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryUrlRewriteMapTest.php
+++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryUrlRewriteDatabaseMapTest.php
@@ -6,28 +6,28 @@
 namespace Magento\CatalogUrlRewrite\Test\Unit\Model\Map;
 
 use Magento\Framework\DB\Select;
-use Magento\CatalogUrlRewrite\Model\Map\DataMapPoolInterface;
-use Magento\CatalogUrlRewrite\Model\Map\DataProductMap;
-use Magento\CatalogUrlRewrite\Model\Map\DataCategoryMap;
-use Magento\CatalogUrlRewrite\Model\Map\DataCategoryUsedInProductsMap;
-use Magento\CatalogUrlRewrite\Model\Map\DataCategoryUrlRewriteMap;
+use Magento\CatalogUrlRewrite\Model\Map\HashMapPool;
+use Magento\CatalogUrlRewrite\Model\Map\DataProductHashMap;
+use Magento\CatalogUrlRewrite\Model\Map\DataCategoryHashMap;
+use Magento\CatalogUrlRewrite\Model\Map\DataCategoryUsedInProductsHashMap;
+use Magento\CatalogUrlRewrite\Model\Map\DataCategoryUrlRewriteDatabaseMap;
 use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
 use Magento\Framework\DB\Adapter\AdapterInterface;
 use Magento\Framework\App\ResourceConnection;
 use Magento\Framework\DB\TemporaryTableService;
 
 /**
- * Class DataCategoryUrlRewriteMapTest
+ * Class DataCategoryUrlRewriteDatabaseMapTest
  */
-class DataCategoryUrlRewriteMapTest extends \PHPUnit_Framework_TestCase
+class DataCategoryUrlRewriteDatabaseMapTest extends \PHPUnit_Framework_TestCase
 {
-    /** @var DataMapPoolInterface|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var HashMapPool|\PHPUnit_Framework_MockObject_MockObject */
     private $dataMapPoolMock;
 
-    /** @var DataCategoryMap|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var DataCategoryHashMap|\PHPUnit_Framework_MockObject_MockObject */
     private $dataCategoryMapMock;
 
-    /** @var DataCategoryUsedInProductsMap|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var DataCategoryUsedInProductsHashMap|\PHPUnit_Framework_MockObject_MockObject */
     private $dataCategoryUsedInProductsMapMock;
 
     /** @var TemporaryTableService|\PHPUnit_Framework_MockObject_MockObject */
@@ -36,15 +36,15 @@ class DataCategoryUrlRewriteMapTest extends \PHPUnit_Framework_TestCase
     /** @var ResourceConnection|\PHPUnit_Framework_MockObject_MockObject */
     private $connectionMock;
 
-    /** @var DataCategoryUrlRewriteMap|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var DataCategoryUrlRewriteDatabaseMap|\PHPUnit_Framework_MockObject_MockObject */
     private $model;
 
     protected function setUp()
     {
-        $this->dataMapPoolMock = $this->getMock(DataMapPoolInterface::class);
-        $this->dataCategoryMapMock = $this->getMock(DataProductMap::class, [], [], '', false);
+        $this->dataMapPoolMock = $this->getMock(HashMapPool::class, [], [], '', false);
+        $this->dataCategoryMapMock = $this->getMock(DataProductHashMap::class, [], [], '', false);
         $this->dataCategoryUsedInProductsMapMock = $this->getMock(
-            DataCategoryUsedInProductsMap::class,
+            DataCategoryUsedInProductsHashMap::class,
             [],
             [],
             '',
@@ -58,12 +58,11 @@ class DataCategoryUrlRewriteMapTest extends \PHPUnit_Framework_TestCase
             ->willReturnOnConsecutiveCalls($this->dataCategoryUsedInProductsMapMock, $this->dataCategoryMapMock);
 
         $this->model = (new ObjectManager($this))->getObject(
-            DataCategoryUrlRewriteMap::class,
+            DataCategoryUrlRewriteDatabaseMap::class,
             [
                 'connection' => $this->connectionMock,
                 'dataMapPool' => $this->dataMapPoolMock,
-                'temporaryTableService' => $this->temporaryTableServiceMock,
-                'mapData' => [],
+                'temporaryTableService' => $this->temporaryTableServiceMock
             ]
         );
     }
@@ -92,7 +91,7 @@ class DataCategoryUrlRewriteMapTest extends \PHPUnit_Framework_TestCase
             ->willReturn($selectMock);
         $connectionMock->expects($this->any())
             ->method('fetchAll')
-            ->willReturnOnConsecutiveCalls($productStoreIds, $productStoreIds[3]);
+            ->willReturn($productStoreIds[3]);
         $selectMock->expects($this->any())
             ->method('from')
             ->willReturnSelf();
@@ -121,7 +120,6 @@ class DataCategoryUrlRewriteMapTest extends \PHPUnit_Framework_TestCase
             )
             ->willReturn('tempTableName');
 
-        $this->assertEquals($productStoreIds, $this->model->getAllData(1));
         $this->assertEquals($productStoreIds[3], $this->model->getData(1, '3_1'));
     }
 }
diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryUsedInProductsMapTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryUsedInProductsHashMapTest.php
similarity index 75%
rename from app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryUsedInProductsMapTest.php
rename to app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryUsedInProductsHashMapTest.php
index 16c0e4e8156..0647c30b43f 100644
--- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryUsedInProductsMapTest.php
+++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataCategoryUsedInProductsHashMapTest.php
@@ -6,39 +6,39 @@
 namespace Magento\CatalogUrlRewrite\Test\Unit\Model\Map;
 
 use Magento\Framework\DB\Select;
-use Magento\CatalogUrlRewrite\Model\Map\DataMapPoolInterface;
-use Magento\CatalogUrlRewrite\Model\Map\DataProductMap;
-use Magento\CatalogUrlRewrite\Model\Map\DataCategoryMap;
-use Magento\CatalogUrlRewrite\Model\Map\DataCategoryUsedInProductsMap;
+use Magento\CatalogUrlRewrite\Model\Map\HashMapPool;
+use Magento\CatalogUrlRewrite\Model\Map\DataProductHashMap;
+use Magento\CatalogUrlRewrite\Model\Map\DataCategoryHashMap;
+use Magento\CatalogUrlRewrite\Model\Map\DataCategoryUsedInProductsHashMap;
 use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
 use Magento\Framework\DB\Adapter\AdapterInterface;
 use Magento\Framework\App\ResourceConnection;
 
 /**
- * Class DataCategoryUsedInProductsMapTest
+ * Class DataCategoryUsedInProductsHashMapTest
  */
-class DataCategoryUsedInProductsMapTest extends \PHPUnit_Framework_TestCase
+class DataCategoryUsedInProductsHashMapTest extends \PHPUnit_Framework_TestCase
 {
-    /** @var DataMapPoolInterface|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var HashMapPool|\PHPUnit_Framework_MockObject_MockObject */
     private $dataMapPoolMock;
 
-    /** @var DataCategoryMap|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var DataCategoryHashMap|\PHPUnit_Framework_MockObject_MockObject */
     private $dataCategoryMapMock;
 
-    /** @var DataProductMap|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var DataProductHashMap|\PHPUnit_Framework_MockObject_MockObject */
     private $dataProductMapMock;
 
     /** @var ResourceConnection|\PHPUnit_Framework_MockObject_MockObject */
     private $connectionMock;
 
-    /** @var DataCategoryUsedInProductsMap|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var DataCategoryUsedInProductsHashMap|\PHPUnit_Framework_MockObject_MockObject */
     private $model;
 
     protected function setUp()
     {
-        $this->dataMapPoolMock = $this->getMock(DataMapPoolInterface::class);
-        $this->dataCategoryMapMock = $this->getMock(DataCategoryMap::class, [], [], '', false);
-        $this->dataProductMapMock = $this->getMock(DataProductMap::class, [], [], '', false);
+        $this->dataMapPoolMock = $this->getMock(HashMapPool::class, [], [], '', false);
+        $this->dataCategoryMapMock = $this->getMock(DataCategoryHashMap::class, [], [], '', false);
+        $this->dataProductMapMock = $this->getMock(DataProductHashMap::class, [], [], '', false);
         $this->connectionMock = $this->getMock(ResourceConnection::class, [], [], '', false);
 
         $this->dataMapPoolMock->expects($this->any())
@@ -53,11 +53,10 @@ class DataCategoryUsedInProductsMapTest extends \PHPUnit_Framework_TestCase
             );
 
         $this->model = (new ObjectManager($this))->getObject(
-            DataCategoryUsedInProductsMap::class,
+            DataCategoryUsedInProductsHashMap::class,
             [
                 'connection' => $this->connectionMock,
-                'dataMapPool' => $this->dataMapPoolMock,
-                'mapData' => [],
+                'hashMapPool' => $this->dataMapPoolMock
             ]
         );
     }
@@ -93,10 +92,10 @@ class DataCategoryUsedInProductsMapTest extends \PHPUnit_Framework_TestCase
             ->willReturnSelf();
         $this->dataMapPoolMock->expects($this->at(4))
             ->method('resetDataMap')
-            ->with(DataProductMap::class, 1);
+            ->with(DataProductHashMap::class, 1);
         $this->dataMapPoolMock->expects($this->at(5))
             ->method('resetDataMap')
-            ->with(DataCategoryMap::class, 1);
+            ->with(DataCategoryHashMap::class, 1);
 
         $this->assertEquals($categoryIds, $this->model->getAllData(1));
         $this->assertEquals($categoryIds[2], $this->model->getData(1, 2));
diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataProductMapTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataProductHashMapTest.php
similarity index 83%
rename from app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataProductMapTest.php
rename to app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataProductHashMapTest.php
index ae0aab97ae8..024c3ee4911 100644
--- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataProductMapTest.php
+++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataProductHashMapTest.php
@@ -9,9 +9,9 @@ use Magento\Catalog\Model\ResourceModel\Category\Collection;
 use Magento\Catalog\Model\ResourceModel\Category as CategoryResource;
 use Magento\Framework\DB\Select;
 use Magento\Catalog\Model\ProductRepository;
-use Magento\CatalogUrlRewrite\Model\Map\DataMapPoolInterface;
-use Magento\CatalogUrlRewrite\Model\Map\DataProductMap;
-use Magento\CatalogUrlRewrite\Model\Map\DataCategoryMap;
+use Magento\CatalogUrlRewrite\Model\Map\HashMapPool;
+use Magento\CatalogUrlRewrite\Model\Map\DataProductHashMap;
+use Magento\CatalogUrlRewrite\Model\Map\DataCategoryHashMap;
 use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
 use Magento\Framework\DB\Adapter\AdapterInterface;
 use Magento\Framework\App\ResourceConnection;
@@ -19,14 +19,14 @@ use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
 use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
 
 /**
- * Class DataProductMapTest
+ * Class DataProductHashMapTest
  */
-class DataProductMapTest extends \PHPUnit_Framework_TestCase
+class DataProductHashMapTest extends \PHPUnit_Framework_TestCase
 {
-    /** @var DataMapPoolInterface|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var HashMapPool|\PHPUnit_Framework_MockObject_MockObject */
     private $dataMapPoolMock;
 
-    /** @var DataCategoryMap|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var DataCategoryHashMap|\PHPUnit_Framework_MockObject_MockObject */
     private $dataCategoryMapMock;
 
     /**
@@ -39,13 +39,13 @@ class DataProductMapTest extends \PHPUnit_Framework_TestCase
      */
     private $productCollectionMock;
 
-    /** @var DataProductMap|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var DataProductHashMap|\PHPUnit_Framework_MockObject_MockObject */
     private $model;
 
     protected function setUp()
     {
-        $this->dataMapPoolMock = $this->getMock(DataMapPoolInterface::class);
-        $this->dataCategoryMapMock = $this->getMock(DataCategoryMap::class, [], [], '', false);
+        $this->dataMapPoolMock = $this->getMock(HashMapPool::class, [], [], '', false);
+        $this->dataCategoryMapMock = $this->getMock(DataCategoryHashMap::class, [], [], '', false);
         $this->collectionFactoryMock = $this->getMock(CollectionFactory::class, ['create'], [], '', false);
         $this->productCollectionMock = $this->getMock(
             ProductCollection::class,
@@ -64,11 +64,10 @@ class DataProductMapTest extends \PHPUnit_Framework_TestCase
             ->willReturn($this->dataCategoryMapMock);
 
         $this->model = (new ObjectManager($this))->getObject(
-            DataProductMap::class,
+            DataProductHashMap::class,
             [
                 'collectionFactory' => $this->collectionFactoryMock,
-                'dataMapPool' => $this->dataMapPoolMock,
-                'mapData' => [],
+                'hashMapPool' => $this->dataMapPoolMock
             ]
         );
     }
@@ -110,7 +109,7 @@ class DataProductMapTest extends \PHPUnit_Framework_TestCase
             ->willReturn([]);
         $this->dataMapPoolMock->expects($this->any())
             ->method('resetDataMap')
-            ->with(DataCategoryMap::class, 1);
+            ->with(DataCategoryHashMap::class, 1);
         $this->assertEquals($productIds, $this->model->getAllData(1));
         $this->assertEquals($productIds[2], $this->model->getData(1, 2));
         $this->assertEquals($productIdsOther, $this->model->getAllData(2));
diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataProductUrlRewriteMapTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataProductUrlRewriteDatabaseMapTest.php
similarity index 73%
rename from app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataProductUrlRewriteMapTest.php
rename to app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataProductUrlRewriteDatabaseMapTest.php
index cf52346e112..5999b884a47 100644
--- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataProductUrlRewriteMapTest.php
+++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataProductUrlRewriteDatabaseMapTest.php
@@ -6,23 +6,23 @@
 namespace Magento\CatalogUrlRewrite\Test\Unit\Model\Map;
 
 use Magento\Framework\DB\Select;
-use Magento\CatalogUrlRewrite\Model\Map\DataMapPoolInterface;
-use Magento\CatalogUrlRewrite\Model\Map\DataProductMap;
-use Magento\CatalogUrlRewrite\Model\Map\DataCategoryUrlRewriteMap;
+use Magento\CatalogUrlRewrite\Model\Map\HashMapPool;
+use Magento\CatalogUrlRewrite\Model\Map\DataProductHashMap;
+use Magento\CatalogUrlRewrite\Model\Map\DataProductUrlRewriteDatabaseMap;
 use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
 use Magento\Framework\DB\Adapter\AdapterInterface;
 use Magento\Framework\App\ResourceConnection;
 use Magento\Framework\DB\TemporaryTableService;
 
 /**
- * Class DataProductUrlRewriteMapTest
+ * Class DataProductUrlRewriteDatabaseMapTest
  */
-class DataProductUrlRewriteMapTest extends \PHPUnit_Framework_TestCase
+class DataProductUrlRewriteDatabaseMapTest extends \PHPUnit_Framework_TestCase
 {
-    /** @var DataMapPoolInterface|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var HashMapPool|\PHPUnit_Framework_MockObject_MockObject */
     private $dataMapPoolMock;
 
-    /** @var DataProductMap|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var DataProductHashMap|\PHPUnit_Framework_MockObject_MockObject */
     private $dataProductMapMock;
 
     /** @var TemporaryTableService|\PHPUnit_Framework_MockObject_MockObject */
@@ -31,13 +31,13 @@ class DataProductUrlRewriteMapTest extends \PHPUnit_Framework_TestCase
     /** @var ResourceConnection|\PHPUnit_Framework_MockObject_MockObject */
     private $connectionMock;
 
-    /** @var DataProductMap|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var DataProductUrlRewriteDatabaseMap|\PHPUnit_Framework_MockObject_MockObject */
     private $model;
 
     protected function setUp()
     {
-        $this->dataMapPoolMock = $this->getMock(DataMapPoolInterface::class);
-        $this->dataProductMapMock = $this->getMock(DataProductMap::class, [], [], '', false);
+        $this->dataMapPoolMock = $this->getMock(HashMapPool::class, [], [], '', false);
+        $this->dataProductMapMock = $this->getMock(DataProductHashMap::class, [], [], '', false);
         $this->temporaryTableServiceMock = $this->getMock(TemporaryTableService::class, [], [], '', false);
         $this->connectionMock = $this->getMock(ResourceConnection::class, [], [], '', false);
 
@@ -46,12 +46,11 @@ class DataProductUrlRewriteMapTest extends \PHPUnit_Framework_TestCase
             ->willReturn($this->dataProductMapMock);
 
         $this->model = (new ObjectManager($this))->getObject(
-            DataCategoryUrlRewriteMap::class,
+            DataProductUrlRewriteDatabaseMap::class,
             [
                 'connection' => $this->connectionMock,
                 'dataMapPool' => $this->dataMapPoolMock,
-                'temporaryTableService' => $this->temporaryTableServiceMock,
-                'mapData' => [],
+                'temporaryTableService' => $this->temporaryTableServiceMock
             ]
         );
     }
@@ -69,11 +68,6 @@ class DataProductUrlRewriteMapTest extends \PHPUnit_Framework_TestCase
             '5' => ['store_id' => 2, 'product_id' => 2],
         ];
 
-        $productStoreIdsExpectedMap = [
-            '1' => [1, 2, 3],
-            '2' => [1, 2],
-        ];
-
         $connectionMock = $this->getMock(AdapterInterface::class);
         $selectMock = $this->getMock(Select::class, [], [], '', false);
 
@@ -85,7 +79,7 @@ class DataProductUrlRewriteMapTest extends \PHPUnit_Framework_TestCase
             ->willReturn($selectMock);
         $connectionMock->expects($this->any())
             ->method('fetchAll')
-            ->willReturnOnConsecutiveCalls($productStoreIds, $productStoreIdsExpectedMap);
+            ->willReturn($productStoreIds[3]);
         $selectMock->expects($this->any())
             ->method('from')
             ->willReturnSelf();
@@ -113,7 +107,6 @@ class DataProductUrlRewriteMapTest extends \PHPUnit_Framework_TestCase
             )
             ->willReturn('tempTableName');
 
-        $this->assertEquals($productStoreIds, $this->model->getAllData(1));
-        $this->assertEquals($productStoreIdsExpectedMap, $this->model->getData(1, '3_1'));
+        $this->assertEquals($productStoreIds[3], $this->model->getData(1, '3_1'));
     }
 }
diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataMapPoolTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/HashMapPoolTest.php
similarity index 63%
rename from app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataMapPoolTest.php
rename to app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/HashMapPoolTest.php
index 0bfe13a8367..213e56595e9 100644
--- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/DataMapPoolTest.php
+++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/HashMapPoolTest.php
@@ -6,20 +6,20 @@
 namespace Magento\CatalogUrlRewrite\Test\Unit\Model\Map;
 
 use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
-use Magento\CatalogUrlRewrite\Model\Map\DataMapPool;
-use Magento\CatalogUrlRewrite\Model\Map\DataCategoryMap;
-use Magento\CatalogUrlRewrite\Model\Map\DataProductMap;
+use Magento\CatalogUrlRewrite\Model\Map\HashMapPool;
+use Magento\CatalogUrlRewrite\Model\Map\DataCategoryHashMap;
+use Magento\CatalogUrlRewrite\Model\Map\DataProductHashMap;
 use Magento\Framework\ObjectManagerInterface;
 
 /**
- * Class DataMapPoolTest
+ * Class HashMapPoolTest
  */
-class DataMapPoolTest extends \PHPUnit_Framework_TestCase
+class HashMapPoolTest extends \PHPUnit_Framework_TestCase
 {
     /** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
     private $objectManagerMock;
 
-    /** @var DataMapPool|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var HashMapPool|\PHPUnit_Framework_MockObject_MockObject */
     private $model;
 
     protected function setUp()
@@ -27,7 +27,7 @@ class DataMapPoolTest extends \PHPUnit_Framework_TestCase
         $this->objectManagerMock = $this->getMock(ObjectManagerInterface::class);
 
         $this->model = (new ObjectManager($this))->getObject(
-            DataMapPool::class,
+            HashMapPool::class,
             [
                 'objectManager' => $this->objectManagerMock,
             ]
@@ -39,16 +39,16 @@ class DataMapPoolTest extends \PHPUnit_Framework_TestCase
      */
     public function testGetDataMap()
     {
-        $dataCategoryMapMock = $this->getMock(DataCategoryMap::class, [], [], '', false);
-        $dataProductMapMock = $this->getMock(DataProductMap::class, [], [], '', false);
-        $dataProductMapMockOtherCategory = $this->getMock(DataProductMap::class, [], [], '', false);
+        $dataCategoryMapMock = $this->getMock(DataCategoryHashMap::class, [], [], '', false);
+        $dataProductMapMock = $this->getMock(DataProductHashMap::class, [], [], '', false);
+        $dataProductMapMockOtherCategory = $this->getMock(DataProductHashMap::class, [], [], '', false);
 
         $this->objectManagerMock->expects($this->any())
             ->method('create')
             ->willReturnOnConsecutiveCalls($dataCategoryMapMock, $dataProductMapMock, $dataProductMapMockOtherCategory);
-        $this->assertEquals($dataCategoryMapMock, $this->model->getDataMap(DataCategoryMap::class, 1));
-        $this->assertEquals($dataCategoryMapMock, $this->model->getDataMap(DataCategoryMap::class, 1));
-        $this->assertEquals($dataProductMapMock, $this->model->getDataMap(DataProductMap::class, 1));
-        $this->assertEquals($dataProductMapMockOtherCategory, $this->model->getDataMap(DataCategoryMap::class, 2));
+        $this->assertEquals($dataCategoryMapMock, $this->model->getDataMap(DataCategoryHashMap::class, 1));
+        $this->assertEquals($dataCategoryMapMock, $this->model->getDataMap(DataCategoryHashMap::class, 1));
+        $this->assertEquals($dataProductMapMock, $this->model->getDataMap(DataProductHashMap::class, 1));
+        $this->assertEquals($dataProductMapMockOtherCategory, $this->model->getDataMap(DataCategoryHashMap::class, 2));
     }
 }
diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/UrlRewriteMapTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/UrlRewriteFinderTest.php
similarity index 68%
rename from app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/UrlRewriteMapTest.php
rename to app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/UrlRewriteFinderTest.php
index c6ea0f0ce44..6b79d5e2f8a 100644
--- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/UrlRewriteMapTest.php
+++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Map/UrlRewriteFinderTest.php
@@ -6,20 +6,20 @@
 namespace Magento\CatalogUrlRewrite\Test\Unit\Model\Map;
 
 use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
-use Magento\CatalogUrlRewrite\Model\Map\UrlRewriteMap;
-use Magento\CatalogUrlRewrite\Model\Map\DataMapPoolInterface;
+use Magento\CatalogUrlRewrite\Model\Map\UrlRewriteFinder;
+use Magento\CatalogUrlRewrite\Model\Map\DatabaseMapPool;
 use Magento\UrlRewrite\Model\UrlFinderInterface;
 use Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory;
 use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
-use Magento\CatalogUrlRewrite\Model\Map\DataProductUrlRewriteMap;
-use Magento\CatalogUrlRewrite\Model\Map\DataCategoryUrlRewriteMap;
+use Magento\CatalogUrlRewrite\Model\Map\DataCategoryUrlRewriteDatabaseMap;
+use Magento\CatalogUrlRewrite\Model\Map\DataProductUrlRewriteDatabaseMap;
 
 /**
- * Class DataProductUrlRewriteMapTest
+ * Class UrlRewriteFinderTest
  */
-class UrlRewriteMapTest extends \PHPUnit_Framework_TestCase
+class UrlRewriteFinderTest extends \PHPUnit_Framework_TestCase
 {
-    /** @var DataMapPoolInterface|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var DatabaseMapPool|\PHPUnit_Framework_MockObject_MockObject */
     private $dataMapPoolMock;
 
     /** @var UrlRewriteFactory|\PHPUnit_Framework_MockObject_MockObject */
@@ -31,12 +31,12 @@ class UrlRewriteMapTest extends \PHPUnit_Framework_TestCase
     /** @var UrlFinderInterface|\PHPUnit_Framework_MockObject_MockObject */
     private $urlFinderMock;
 
-    /** @var UrlRewriteMap|\PHPUnit_Framework_MockObject_MockObject */
+    /** @var UrlRewriteFinder|\PHPUnit_Framework_MockObject_MockObject */
     private $model;
 
     protected function setUp()
     {
-        $this->dataMapPoolMock = $this->getMock(DataMapPoolInterface::class);
+        $this->dataMapPoolMock = $this->getMock(DatabaseMapPool::class, [], [], '', false);
         $this->urlFinderMock = $this->getMock(UrlFinderInterface::class);
         $this->urlRewriteFactoryMock = $this->getMock(UrlRewriteFactory::class, ['create'], [], '', false);
         $this->urlRewritePrototypeMock = new UrlRewrite();
@@ -46,9 +46,9 @@ class UrlRewriteMapTest extends \PHPUnit_Framework_TestCase
             ->willReturn($this->urlRewritePrototypeMock);
 
         $this->model = (new ObjectManager($this))->getObject(
-            UrlRewriteMap::class,
+            UrlRewriteFinder::class,
             [
-                'dataMapPool' => $this->dataMapPoolMock,
+                'databaseMapPool' => $this->dataMapPoolMock,
                 'urlFinder' => $this->urlFinderMock,
                 'urlRewriteFactory' => $this->urlRewriteFactoryMock
             ]
@@ -68,13 +68,13 @@ class UrlRewriteMapTest extends \PHPUnit_Framework_TestCase
             ->method('findAllByData')
             ->willReturn($expected);
 
-        $this->assertEquals($expected, $this->model->getByIdentifiers(1, 1, UrlRewriteMap::ENTITY_TYPE_CATEGORY));
-        $this->assertEquals($expected, $this->model->getByIdentifiers(1, 1, UrlRewriteMap::ENTITY_TYPE_PRODUCT));
-        $this->assertEquals($expected, $this->model->getByIdentifiers('a', 1, UrlRewriteMap::ENTITY_TYPE_PRODUCT), 1);
-        $this->assertEquals($expected, $this->model->getByIdentifiers('a', 'a', UrlRewriteMap::ENTITY_TYPE_PRODUCT), 1);
-        $this->assertEquals($expected, $this->model->getByIdentifiers(1, 'a', UrlRewriteMap::ENTITY_TYPE_PRODUCT), 1);
-        $this->assertEquals($expected, $this->model->getByIdentifiers(1, 1, 'cms', 1));
-        $this->assertEquals($expected, $this->model->getByIdentifiers(1, 1, 'cms'));
+        $this->assertEquals($expected, $this->model->findAllByData(1, 1, UrlRewriteFinder::ENTITY_TYPE_CATEGORY));
+        $this->assertEquals($expected, $this->model->findAllByData(1, 1, UrlRewriteFinder::ENTITY_TYPE_PRODUCT));
+        $this->assertEquals($expected, $this->model->findAllByData('a', 1, UrlRewriteFinder::ENTITY_TYPE_PRODUCT), 1);
+        $this->assertEquals($expected, $this->model->findAllByData('a', 'a', UrlRewriteFinder::ENTITY_TYPE_PRODUCT), 1);
+        $this->assertEquals($expected, $this->model->findAllByData(1, 'a', UrlRewriteFinder::ENTITY_TYPE_PRODUCT), 1);
+        $this->assertEquals($expected, $this->model->findAllByData(1, 1, 'cms', 1));
+        $this->assertEquals($expected, $this->model->findAllByData(1, 1, 'cms'));
     }
 
     /**
@@ -97,10 +97,10 @@ class UrlRewriteMapTest extends \PHPUnit_Framework_TestCase
             ]
         ];
 
-        $dataProductMapMock = $this->getMock(DataProductUrlRewriteMap::class, [], [], '', false);
+        $dataProductMapMock = $this->getMock(DataProductUrlRewriteDatabaseMap::class, [], [], '', false);
         $this->dataMapPoolMock->expects($this->once())
             ->method('getDataMap')
-            ->with(DataProductUrlRewriteMap::class, 1)
+            ->with(DataProductUrlRewriteDatabaseMap::class, 1)
             ->willReturn($dataProductMapMock);
 
         $this->urlFinderMock->expects($this->never())
@@ -111,7 +111,7 @@ class UrlRewriteMapTest extends \PHPUnit_Framework_TestCase
             ->method('getData')
             ->willReturn($data);
 
-        $urlRewriteResultArray = $this->model->getByIdentifiers(1, 1, UrlRewriteMap::ENTITY_TYPE_PRODUCT, 1);
+        $urlRewriteResultArray = $this->model->findAllByData(1, 1, UrlRewriteFinder::ENTITY_TYPE_PRODUCT, 1);
         $this->assertEquals($data[0], $urlRewriteResultArray[0]->toArray());
     }
 
@@ -135,10 +135,10 @@ class UrlRewriteMapTest extends \PHPUnit_Framework_TestCase
             ]
         ];
 
-        $dataCategoryMapMock = $this->getMock(DataCategoryUrlRewriteMap::class, [], [], '', false);
+        $dataCategoryMapMock = $this->getMock(DataCategoryUrlRewriteDatabaseMap::class, [], [], '', false);
         $this->dataMapPoolMock->expects($this->once())
             ->method('getDataMap')
-            ->with(DataCategoryUrlRewriteMap::class, 1)
+            ->with(DataCategoryUrlRewriteDatabaseMap::class, 1)
             ->willReturn($dataCategoryMapMock);
 
         $this->urlFinderMock->expects($this->never())
@@ -149,7 +149,7 @@ class UrlRewriteMapTest extends \PHPUnit_Framework_TestCase
             ->method('getData')
             ->willReturn($data);
 
-        $urlRewriteResultArray = $this->model->getByIdentifiers(1, 1, UrlRewriteMap::ENTITY_TYPE_CATEGORY, 1);
+        $urlRewriteResultArray = $this->model->findAllByData(1, 1, UrlRewriteFinder::ENTITY_TYPE_CATEGORY, 1);
         $this->assertEquals($data[0], $urlRewriteResultArray[0]->toArray());
     }
 }
diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Product/CurrentUrlRewritesRegeneratorTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Product/CurrentUrlRewritesRegeneratorTest.php
index f093145cea5..61fe9643f0e 100644
--- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Product/CurrentUrlRewritesRegeneratorTest.php
+++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Product/CurrentUrlRewritesRegeneratorTest.php
@@ -55,7 +55,7 @@ class CurrentUrlRewritesRegeneratorTest extends \PHPUnit_Framework_TestCase
             ->disableOriginalConstructor()->getMock();
         $this->objectRegistry = $this->getMockBuilder(\Magento\CatalogUrlRewrite\Model\ObjectRegistry::class)
             ->disableOriginalConstructor()->getMock();
-        $this->urlRewriteMap = $this->getMockBuilder(\Magento\CatalogUrlRewrite\Model\Map\UrlRewriteMap::class)
+        $this->urlRewriteMap = $this->getMockBuilder(\Magento\CatalogUrlRewrite\Model\Map\UrlRewriteFinder::class)
             ->disableOriginalConstructor()->getMock();
         $this->urlRewriteFactory->expects($this->once())->method('create')
             ->willReturn($this->urlRewrite);
diff --git a/app/code/Magento/CatalogUrlRewrite/etc/di.xml b/app/code/Magento/CatalogUrlRewrite/etc/di.xml
index 877638026a5..9ea21bce365 100644
--- a/app/code/Magento/CatalogUrlRewrite/etc/di.xml
+++ b/app/code/Magento/CatalogUrlRewrite/etc/di.xml
@@ -6,7 +6,6 @@
  */
 -->
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
-    <preference for="Magento\CatalogUrlRewrite\Model\Map\DataMapPoolInterface" type="Magento\CatalogUrlRewrite\Model\Map\DataMapPool" />
     <type name="Magento\Catalog\Block\Widget\Link">
         <arguments>
             <argument name="urlFinder" xsi:type="object">Magento\CatalogUrlRewrite\Model\Storage\DbStorage</argument>
diff --git a/app/code/Magento/UrlRewrite/Model/UrlRewritesSet.php b/app/code/Magento/UrlRewrite/Model/UrlRewritesSet.php
index 184eb9486a2..b395a922d65 100644
--- a/app/code/Magento/UrlRewrite/Model/UrlRewritesSet.php
+++ b/app/code/Magento/UrlRewrite/Model/UrlRewritesSet.php
@@ -14,6 +14,7 @@ use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
  */
 class UrlRewritesSet
 {
+    const SEPARATOR = '_';
     /**
      * @var $rewritesArray[]
      */
@@ -27,10 +28,9 @@ class UrlRewritesSet
      */
     public function merge(array $urlRewritesArray)
     {
-        $separator = '_';
         foreach ($urlRewritesArray as $urlRewrite) {
-            $key = $urlRewrite->getRequestPath() . $separator . $urlRewrite->getStoreId();
-            if ($key !== $separator) {
+            $key = $urlRewrite->getRequestPath() . self::SEPARATOR . $urlRewrite->getStoreId();
+            if ($key !== self::SEPARATOR) {
                 $this->data[$key] = $urlRewrite;
             } else {
                 $this->data[] = $urlRewrite;
diff --git a/app/code/Magento/UrlRewrite/Test/Unit/Model/UrlRewritesSetTest.php b/app/code/Magento/UrlRewrite/Test/Unit/Model/UrlRewritesSetTest.php
index ce5b944cb3b..aaabb1499b7 100644
--- a/app/code/Magento/UrlRewrite/Test/Unit/Model/UrlRewritesSetTest.php
+++ b/app/code/Magento/UrlRewrite/Test/Unit/Model/UrlRewritesSetTest.php
@@ -55,20 +55,6 @@ class UrlRewritesSetTest extends \PHPUnit_Framework_TestCase
         $this->assertEmpty($this->urlRewritesSet->getData());
     }
 
-    /**
-     * Run test getData method when data is not empty
-     *
-     * @return void
-     */
-    public function testGetDataWhenNotEmpty()
-    {
-        $data = new \ReflectionProperty($this->urlRewritesSet, 'data');
-        $data->setAccessible(true);
-        $data->setValue($this->urlRewritesSet, [new UrlRewrite()]);
-        $data->setAccessible(false);
-        $this->assertNotEmpty($this->urlRewritesSet->getData());
-    }
-
     /**
      * Data provider  for testMerge
      *
diff --git a/lib/internal/Magento/Framework/DB/TemporaryTableService.php b/lib/internal/Magento/Framework/DB/TemporaryTableService.php
index 19ad906b84c..36223d5b060 100644
--- a/lib/internal/Magento/Framework/DB/TemporaryTableService.php
+++ b/lib/internal/Magento/Framework/DB/TemporaryTableService.php
@@ -24,7 +24,7 @@ class TemporaryTableService
     /**
      * @var AdapterInterface[]
      */
-    private $createdTables = [];
+    private $createdTableAdapters = [];
 
     /**
      * @param \Magento\Framework\Math\Random $random
@@ -46,9 +46,10 @@ class TemporaryTableService
      *           [
      *              'PRIMARY' => ['primary_id'],
      *              'some_single_field_index' => ['field'],
-     *              'some_multiple_field_index' => ['field1', 'field2'],
+     *              'UNQ_some_multiple_field_index' => ['field1', 'field2'],
      *           ]
      *          )
+     * Note that indexes names with UNQ_ prefix, will be created as unique
      *
      * @param Select $select
      * @param AdapterInterface $adapter
@@ -70,7 +71,7 @@ class TemporaryTableService
         foreach ($indexes as $indexName => $columns) {
             $renderedColumns = implode(',', array_map([$adapter, 'quoteIdentifier'], $columns));
 
-            $indexType = sprintf('INDEX %s USING %s', $adapter->quoteIdentifier($indexName), $indexMethod);
+            $indexType = sprintf('INDEX %s USING %s', $adapter->quoteIdentifier($indexName), "{$indexMethod}");
 
             if ($indexName === 'PRIMARY') {
                 $indexType = 'PRIMARY KEY';
@@ -85,8 +86,8 @@ class TemporaryTableService
             'CREATE TEMPORARY TABLE %s %s ENGINE=%s IGNORE (%s)',
             $adapter->quoteIdentifier($name),
             $indexStatements ? '(' . implode(',', $indexStatements) . ')' : '',
-            $engine,
-            (string)$select
+            "{$engine}",
+            "{$select}"
         );
 
         $adapter->query(
@@ -94,28 +95,30 @@ class TemporaryTableService
             $select->getBind()
         );
 
-        $this->createdTables[$name] = $adapter;
+        $this->createdTableAdapters[$name] = $adapter;
 
         return $name;
     }
 
     /**
      * Method used to drop a table by name
-     * This class will hold all temporary table names in createdTables array so we can dispose them once we're finished
+     * This class will hold all temporary table names in createdTableAdapters array
+     * so we can dispose them once we're finished
      *
-     * Example: dropTable($previouslySavedTableName)
-     * where $previouslySavedTableName is a variable that you have to save when you use "createFromSelect" method
+     * Example: dropTable($name)
+     * where $name is a variable that holds the name for a previously created temporary  table
+     * by using "createFromSelect" method
      *
      * @param string $name
      * @return bool
      */
     public function dropTable($name)
     {
-        if (!empty($this->createdTables)) {
-            if (isset($this->createdTables[$name]) && !empty($name)) {
-                $adapter = $this->createdTables[$name];
+        if (!empty($this->createdTableAdapters)) {
+            if (isset($this->createdTableAdapters[$name]) && !empty($name)) {
+                $adapter = $this->createdTableAdapters[$name];
                 $adapter->dropTemporaryTable($name);
-                unset($this->createdTables[$name]);
+                unset($this->createdTableAdapters[$name]);
                 return true;
             }
         }
-- 
GitLab