Ankündigung

Einklappen
Keine Ankündigung bisher.

PDO count(*) Tabelle ist langsam

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • #16
    Gemeint ist, der Left Join ist falsch aufgebaut, wenn es wirklich ein Left Join sein soll, muss er umgebaut werden, so wie erc schrieb.
    Hat ein Left Join in der Where Clause ein Kriterium am "offenen Ende", führt das zu einer Einschränkung, die praktisch einen Inner Join ergibt. Damit wird der Left Join Charakter zerstört.

    Das Where Kriterium muss also zum Join Kriterium werden, damit es so wird wie es soll.

    Kommentar


    • #17
      Danke Perry und Erc, was neues gelernt Dann ist es ein Inner Join.

      Muss wohl dann an Xampp liegen. Habe mit "xampp mysql connection slow" Goggle gefragt. Da gabs Tonnenweise Artikel. Ich lass es dann mal bleiben anstatt die Nadel im Heuhaufen zu suchen. Ich kenne mich bei den Konfiguration leider zu wenig aus.

      Kommentar


      • #18
        Das hat aber nichts mit deiner langsamen Query zu tun. Auch Xampp nicht.
        Du stellst nur Vermutungen an ignorierst zudem alles was ich dazu schrieb.

        Wie sieh dein Connect aus?
        Wie ist der SQL Dump deiner DB?

        Da musst du ansetzen.

        Kommentar


        • #19
          Hier mal die Tabllenstruktur:

          HTML-Code:
          --
          -- Tabellenstruktur für Tabelle `shop_products`
          --
          
          CREATE TABLE `shop_products` (
            `id` bigint(20) UNSIGNED NOT NULL,
            `active` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
            `link_id` bigint(20) UNSIGNED DEFAULT '0',
            `roles` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
            `type` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
            `sort_order` int(11) UNSIGNED DEFAULT '0',
            `price` decimal(15,4) DEFAULT NULL,
            `prices` text COLLATE utf8mb4_unicode_ci,
            `has_sale_price` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
            `sku` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
            `gtin` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
            `ean` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
            `upc_code` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
            `status` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'available',
            `quantity` int(11) UNSIGNED DEFAULT '0',
            `weight` decimal(5,2) UNSIGNED DEFAULT '0.00',
            `order_blocks` int(11) UNSIGNED DEFAULT '1',
            `ordered` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
            `shipping_methods` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
            `data` text COLLATE utf8mb4_unicode_ci,
            `date_created` datetime DEFAULT NULL,
            `date_updated` datetime DEFAULT NULL,
            `date_available_yearly` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
            `date_available_from` datetime DEFAULT NULL,
            `date_available_to` datetime DEFAULT NULL,
            `musterable` tinyint(1) UNSIGNED NOT NULL DEFAULT '0'
          ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
          
          --
          -- Indizes der exportierten Tabellen
          --
          
          --
          -- Indizes für die Tabelle `shop_products`
          --
          ALTER TABLE `shop_products`
            ADD PRIMARY KEY (`id`),
            ADD KEY `idx_id` (`id`);
          
          --
          -- AUTO_INCREMENT für exportierte Tabellen
          --
          
          --
          -- AUTO_INCREMENT für Tabelle `shop_products`
          --
          ALTER TABLE `shop_products`
            MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
          COMMIT;

          Code:
          CREATE TABLE `shop_products_lg` (
            `product_id` bigint(11) UNSIGNED NOT NULL,
            `language_id` int(11) UNSIGNED NOT NULL DEFAULT '1',
            `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
            `alias` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT '',
            `intro` text COLLATE utf8mb4_unicode_ci,
            `description` text COLLATE utf8mb4_unicode_ci,
            `image` text COLLATE utf8mb4_unicode_ci,
            `images` text COLLATE utf8mb4_unicode_ci,
            `files` text COLLATE utf8mb4_unicode_ci,
            `data_lg` text COLLATE utf8mb4_unicode_ci,
            `meta_title` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT '',
            `meta_description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT '',
            `meta_keywords` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT '',
            `videos` text COLLATE utf8mb4_unicode_ci,
            `unit` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
            `unit_info` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL
          ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
          
          --
          -- Indizes der exportierten Tabellen
          --
          
          --
          -- Indizes für die Tabelle `shop_products_lg`
          --
          ALTER TABLE `shop_products_lg`
            ADD KEY `language_id` (`language_id`),
            ADD KEY `product_id` (`product_id`);
          COMMIT;

          Bei deiner Explain Ausgabe fehlen die Überschriften.
          Diese hatte es mir leider immer weggeschossen im Editor hier


          Die Pdo Verbindung mache ich folgendermassen:

          PHP-Code:
          /**
           * @param string The database type such as mysql.
           * @param string The database host such as localhost.
           * @param string The database name.
           * @param string The database username.
           * @param string The database password.
           */    
          public function __construct(string $dbTypestring $dbHoststring $dbNamestring $dbUsernamestring $dbPassword)
          {
              try {

                  
          $this->pdo = new PDO($dbType.':host='.$dbHost.'; dbname='.$dbName.''$dbUsername$dbPassword);

                  
          // Set error mode
                  
          $this->pdo->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);

                  
          $this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARESfalse);

                  
          // Sets encoding UTF-8
                  
          $this->pdo->exec("SET CHARACTER SET utf8");


              } catch( 
          PDOException $e ) {
                  throw new 
          Exception('PDO: cannot connect!'0$e);
              }

          Kommentar


          • #20
            PHP-Code:
            $this->pdo->exec("SET CHARACTER SET utf8mb4"); 


            Sollte dein Problem beheben.

            Da du einen Shop hast, brauchst du wahrscheinlich kein utf8mb8 sondern es reicht ein UTF8, da ist die collation die als default gilt utf8_general_ci.
            Diese gibt es auch als utf8mb4_general_ci, kann wohl aber nicht sauber mit Sonderzeichen umgehen, weshalb dann auf utf8mb4_unicode_ci zurückgegriffen wird. Das ist aber langsam, da Mysql da immer erst in die Übersetzungstabelle rein schauen muss und das kostet eben Zeit.
            Datumsfelder sollten zudem keine Collation haben oder wenn dann die XXX_general_ci, sonst gibt das wieder Probleme
            Mysql ist da nicht perfekt, meiner Meinung nach.

            Für welche Lösung du dich entscheidest überlasse ich dir.
            Wenn du Speed willst nimm utf8 ohne das mb4 als Zeichenkodierung, auch wenn die chinesischen Schriftzeichen und Smileys etc dann nicht korrekt gehen, abe rdu hast ja nur einen Shop für DE oder EU denke ich, dann kann man das verschmerzen.

            Kommentar


            • #21
              Wow Protestix vielen Dank für die wertvollen Infos.

              Habe deinen Rat befolgt und nun hat sich die Zeit um die Hälfte halbiert. Mal schauen ob ich mb4 weglasse. Höchstens für die Kommentarefunktion würde es einen Sinn ergeben.

              Vielen Dank euch allen nochmals, ich schätze eure professionelle Hilfe sehr.

              Kommentar


              • #22
                SET CHARACTER SET sollte gar nicht verwendet werden. Die Kodierung sollte im DSN gesetzt werden.

                Kommentar


                • #23
                  Danke Hellbringer, habe ich gerade so gemacht.

                  Kommentar

                  Lädt...
                  X