2

厄介な問題に遭遇しました。

私はシステムを作成しましたが、ユーザーは次のようなメッセージを伝えていると言っています。

メモリ不足 (268435427 バイト必要)

データベース全体のサイズは 12MB で、問題のあるクエリは数か月間正常に実行されており、それほど複雑でも大きくもありません。

データベースは innodb です。私のサーバーには 24GB の RAM が搭載されているため、実際にメモリ不足ではないかと真剣に疑っています。

my.cnf は次のとおりです。

key_buffer = 8000M

max_allowed_pa​​cket = 1M

テーブルキャッシュ = 2048M

sort_buffer_size = 1M

net_buffer_length = 1024M

read_buffer_size = 1M

read_rnd_buffer_size = 24M

innodb_log_file_size = 5M

innodb_log_buffer_size = 8M

innodb_flush_log_at_trx_commit = 1

innodb_lock_wait_timeout = 50

innodb_buffer_pool_size = 1024M

innodb_additional_mem_pool_size = 2M

最大接続数 = 100

query_cache_size = 128M

query_cache_min_res_unit = 1024

query_cache_limit = 16MB

スレッドキャッシュサイズ = 100

max_heap_table_size = 4096MB

Windows のタスク マネージャーを見ると、18.8GB の空き容量が表示されていますが、空き容量は 100MB しかありません。これは Windows 2008 64 ビット サーバーですが、これが問題の原因でしょうか?


クエリは次のとおりです。

$currency     = '(SELECT currencies.symbol
                            FROM parts_trading, currencies
                            WHERE parts_trading.enquiryRef = enquiries.id
                            AND parts_trading.sellingCurrency = currencies.id
                            LIMIT 1
                         )' ;

$amountDueSQL = '(
                         (SELECT SUM(quantity*(parts_trading.sellingNet
                                    +
                                    parts_trading.sellingVat))
                            FROM parts_trading
                            WHERE parts_trading.enquiryRef = enquiries.id
                         )
                         +
                         (SELECT SUM(enquiries_custom_fees.feeAmountNet
                                    +
                                    enquiries_custom_fees.feeAmountVat)
                            FROM enquiries_custom_fees
                            WHERE enquiries_custom_fees.enquiryRef = enquiries.id
                         )
                         )' ;
$amountPaidSQL = 'COALESCE(
                             (SELECT SUM(jobs_payments_advance.amount)
                                FROM jobs_payments_advance
                                WHERE jobs_payments_advance.jobRef = jobs.id
                             ),
                             0
                         )' ;

    $result = $dbh->prepare("SELECT SQL_CALC_FOUND_ROWS jobs.id, jobs_states.state, jobs.creationDate, users.username,
                            entity_details.name, enquiries.id as enquiryId, pendingCancelation,
                            IF(entity_details.paymentTermsRef = 1, # Outer IF condition
                               IF($amountDueSQL-$amountPaidSQL = 0.00, # Inner IF condition
                                  CONCAT('Paid in full (', $currency, $amountDueSQL, ')') # Inner IF TRUE
                               , # End of inner IF TRUE
                                  IF($amountPaidSQL > 0,
                                     CONCAT('Part paid (', $currency, $amountPaidSQL, ')'),
                                     'Unpaid'
                                  )
                               ) # End of inner IF

                            , # End of TRUE for outer IF
                               (SELECT entity_payment_terms.term
                                    FROM entity_details, entity_payment_terms
                                    WHERE entity_details.paymentTermsRef
                                          =
                                          entity_payment_terms.id
                                    AND entity_details.id = enquiries.entityRef
                               ) # End of FALSE for outer IF
                            ) AS payState, enquiries.orderNumber,

                            IF((SELECT COUNT(*)
                                    FROM invoices_out, (SELECT * FROM invoices_out_reference GROUP BY jobRef) AS tb1
                             WHERE invoices_out.id = tb1.invoiceRef
                             AND tb1.jobRef = jobs.id) > 1,
                               'Part-invoiced',
                               (SELECT invoices_out.date
                                    FROM invoices_out, (SELECT * FROM invoices_out_reference GROUP BY jobRef) AS tb1
                             WHERE invoices_out.id = tb1.invoiceRef
                             AND tb1.jobRef = jobs.id)
                             ) AS invoicedDate,

                            enquiries.id AS enquiryId,

                            IF((SELECT COUNT(*)
                                    FROM invoices_out, (SELECT * FROM invoices_out_reference GROUP BY jobRef) AS tb1
                             WHERE invoices_out.id = tb1.invoiceRef
                             AND tb1.jobRef = jobs.id) > 1,
                               'Multiple invoices',
                               (SELECT invoices_out.id
                                    FROM invoices_out, (SELECT * FROM invoices_out_reference GROUP BY jobRef) AS tb1
                             WHERE invoices_out.id = tb1.invoiceRef
                             AND tb1.jobRef = jobs.id)
                             ) AS invoiceNumber,

                            # If the state is 0 (i.e. they have an account, if true find out their payment terms, if false, instead reference the payment state directly.
                            (SELECT MAX(etaDate) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id) AS maxEtaDate,
                            (SELECT COUNT(DISTINCT DATE(etaDate)) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id) AS etaCounts, entity_credit_limits.creditLimit AS cLimit,
                            COALESCE((SELECT 
                                    SUM(qty*parts_trading_buying.buyingNet
                                    /
                                    (SELECT rateVsPound FROM currencies WHERE currencies.id = parts_trading_buying.buyingCurrency))
                                    FROM parts_trading_buying
                                    WHERE parts_trading_buying.enquiryRef = enquiries.id
                                    ), 0
                                    ) AS nonInvoicedBuyingCosts,
                            COALESCE((SELECT 
                                    SUM(feeAmountNet/(SELECT rateVsPound FROM currencies WHERE currencies.id = parts_trading_buying.buyingCurrency))
                                    FROM parts_trading_buying_charges, parts_trading_buying 
                                    WHERE parts_trading_buying_charges.partRef = parts_trading_buying.id
                                    AND parts_trading_buying.enquiryRef = enquiries.id
                                    ), 0
                                ) AS nonInvoicedBuyingFeeCosts,
                            (SELECT
                                SUM(quantity*parts_trading.sellingNet)
                                    /
                                    COALESCE(
                                        (SELECT invoices_out.rate
                                         FROM invoices_out, invoices_out_reference
                                         WHERE invoices_out.id = invoices_out_reference.invoiceRef
                                         AND invoices_out_reference.jobRef = jobs.id
                                         LIMIT 1),
                                        (SELECT rateVsPound
                                         FROM currencies
                                         WHERE currencies.id = parts_trading.sellingCurrency)
                                    )
                             FROM parts_trading
                             WHERE parts_trading.enquiryRef = enquiries.id
                            ) AS sellingParts,
                            COALESCE((SELECT
                                    SUM(enquiries_custom_fees.feeAmountNet)
                                    /
                                    COALESCE(
                                        (SELECT rate
                                         FROM invoices_out, invoices_out_reference
                                         WHERE invoices_out.id = invoices_out_reference.invoiceRef
                                         AND invoices_out_reference.jobRef = jobs.id LIMIT 1),
                                        (SELECT rateVsPound
                                         FROM currencies
                                         WHERE currencies.id = parts_trading.sellingCurrency
                                         )
                                    )
                                    FROM enquiries_custom_fees, parts_trading
                                    WHERE enquiries_custom_fees.enquiryRef = enquiries.id
                                    AND parts_trading.enquiryRef = enquiries.id), 0) AS sellingFees,
                            COALESCE((SELECT
                                    SUM(parts_shipping_out.shippingOutCost)
                                    FROM parts_shipping_out, parts_shipping_arrival_dates, parts_shipping_v2
                                    WHERE parts_shipping_out.arrivalsRef = parts_shipping_arrival_dates.id
                                    AND parts_shipping_arrival_dates.shippingRef = parts_shipping_v2.id
                                    AND parts_shipping_v2.jobRef = jobs.id
                                    ), 0
                                ) AS actualShippingOutFromEua,
                            (SELECT

                                SUM(quantity*parts_trading.sellingNet)
                                    /
                                    COALESCE(
                                        (SELECT invoices_out.rate
                                         FROM invoices_out, invoices_out_reference
                                         WHERE invoices_out.id = invoices_out_reference.invoiceRef
                                         AND invoices_out_reference.jobRef = jobs.id
                                         LIMIT 1),
                                        (SELECT rateVsPound
                                         FROM currencies
                                         WHERE currencies.id = parts_trading.sellingCurrency)
                                    )
                                +
                                COALESCE((SELECT
                                    SUM(enquiries_custom_fees.feeAmountNet)
                                    /
                                    COALESCE(
                                        (SELECT rate
                                         FROM invoices_out, invoices_out_reference
                                         WHERE invoices_out.id = invoices_out_reference.invoiceRef
                                         AND invoices_out_reference.jobRef = jobs.id LIMIT 1),
                                        (SELECT rateVsPound
                                         FROM currencies
                                         WHERE currencies.id = parts_trading.sellingCurrency
                                         )
                                    )
                                    FROM enquiries_custom_fees
                                    WHERE enquiries_custom_fees.enquiryRef = enquiries.id), 0)
                                -
                                COALESCE((SELECT 
                                    SUM(qty*parts_trading_buying.buyingNet
                                    /
                                    (SELECT rateVsPound FROM currencies WHERE currencies.id = parts_trading_buying.buyingCurrency))
                                    FROM parts_trading_buying
                                    WHERE parts_trading_buying.enquiryRef = enquiries.id
                                    ), 0
                                    )
                                -
                                COALESCE((SELECT 
                                    SUM(feeAmountNet/(SELECT rateVsPound FROM currencies WHERE currencies.id = parts_trading_buying.buyingCurrency))
                                    FROM parts_trading_buying_charges, parts_trading_buying 
                                    WHERE parts_trading_buying_charges.partRef = parts_trading_buying.id
                                    AND parts_trading_buying.enquiryRef = enquiries.id
                                    ), 0
                                )
                                -
                                COALESCE((SELECT
                                    SUM(parts_shipping_out.shippingOutCost)
                                    FROM parts_shipping_out, parts_shipping_arrival_dates, parts_shipping_v2
                                    WHERE parts_shipping_out.arrivalsRef = parts_shipping_arrival_dates.id
                                    AND parts_shipping_arrival_dates.shippingRef = parts_shipping_v2.id
                                    AND parts_shipping_v2.jobRef = jobs.id
                                    ), 0
                                )
                                FROM parts_trading, parts_trading_buying
                                WHERE parts_trading.enquiryRef = enquiries.id
                                AND parts_trading_buying.counterpartRef = parts_trading.id
                            ) AS margin
                            FROM jobs,
                            jobs_states, enquiries, users, jobs_payment_status, entity_details
                            LEFT JOIN entity_credit_limits ON entity_details.id = entity_credit_limits.entityRef
                            WHERE jobs.stateRef = jobs_states.id
                            AND IF(paymentStateRef = 0, 1, (jobs_payment_status.id = jobs.paymentStateRef))
                            # ^ If true it causes a result for each payment state (i.e. 3), so we group on state below, shouldn't cause probs.
                            AND jobs.enquiryRef = enquiries.id
                            AND enquiries.entityRef = entity_details.id
                            AND users.id = enquiries.traderRef
                            AND enquiries.traderRef = ?
                                LIMIT ?, ?") ;

PHP 実行メモリを 3.5GB 以上に設定しようとすると、Apache が起動しません (私は xampp を使用しています)。32 ビット バージョンの PHP を使用している必要がありますか? これは INNODB_BUFFER_POOL_SIZE についても同じで、14GB にしたいのですが、そうすると mysql が起動しません。

4

2 に答える 2

1

ほとんどの場合、この種のエラー (メモリ不足 (必要な 268435427 バイト)) が PHP によってスローされるため、これはデータベース関連の問題ではないと思います (無限ループまたは同様のものが問題である可能性があります)。

于 2012-07-05T07:28:11.500 に答える